我正在尝试使用PhoneGap在ipad应用程序(使用worklightV6)下将图片上传到RestFul API中的Websphere Application Server。
我的网络浏览器代码如下所示:
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 类class 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 $一般 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 $一般 com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider $一般 com.sun.jersey.core.impl.provider.entity.XMLListElementProvider $一般 com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider $一般 com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider $一般 com.sun.jersey.json.impl.provider.entity.JSONListElementProvider $常规
提前感谢您的帮助!
答案 0 :(得分:2)
将我的RestFul API更改为:
@POST
@Path("upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response upload(@FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("file") FormDataContentDisposition fileDetail) {
}
以及以下帖子MIMEParsingException in REST(我将mimepull.jar,jersey-multipart.jar添加到我的lib路径中),我设法让它工作了!