我正在尝试在 ipad 应用程序(使用 worklightV6)下使用 PhoneGap 将图片上传到 RestFul API 中的 Websphere 应用程序服务器。
我的网络浏览器代码如下所示:
var photosURI = [];
var manageDeviceDocumentsURI = "http://IP:PORT/****/rest/AmanageDevicesDocuments.upload";
function cameraSuccessCallback(imageURI){
photosURI.push(imageURI);
}
$("#content").on("click", "#takePicture", function(){
cameraOptions = {quality : 20, allowEdit: true, desinationType.FILE_URI };
navigator.camero.getPicture(cameraSuccessCallback, cammeraErrorCallback, cameraOptions);
});
$("#content").on("click", "#uploadPictures", function(){
function fail(error){
alert("An error has occured: Code " + error.code);
console.log("Upload error source " + error.source);
console.log("Upload error target " + error.target);
}
function win(){
alert('transfert ok');
}
var fileURI = photosURI.pop();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "multipart/form-data";
var ft = new FileTransfert();
ft.upload(fileURI, encodeURI(manageDeviceDocumentsURI), win, fail, otpions);
});
我在服务器上的 java 代码如下所示:
@Path("manageDeviceDocuments")
public class ManageDeviceDocuments {
@POST
@Path("upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public JSONArray upload(@Context ServletConfig servletConfig,
@Context HttpHeaders httpHeaders, @Context UriInfo uriInfo,
BufferedInMultiPart bimp) throws IOException {
}
}
我在网络浏览器上收到以下错误:
错误 415:不支持的媒体类型,代码 3 ...
这在服务器上:
Java 类 org.apache.wink.common.model.multipart.BufferedInMultiPart 和 Java 类型类 org.apache.wink.common.model.multipart.BufferedInMultiPart 和 MIME 媒体类型 multipart/form-data;boundary 的消息体阅读器=+++++org.apache.cordova.formBoundary 未找到。与 MIME 媒体类型兼容的注册消息体阅读器为: / -> com.sun.jersey.core.impl.provider.entity.FormProvider com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
com.sun。 jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl .provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun .jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader com.sun.jersey.core.impl.provider.entity.SourceProvider$ DOMSourceReader com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General com.sun.jersey.core.impl.provider.entity.XMLListElementProvider $General com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$一般 com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
预先感谢您的帮助 !