使用ExtJS和Jersey上传文件

我有一个基于ExtJS的应用程序,我想通过Rest的Jersey来上传一个文件,一张图片,但是我不能这么做,这有可能吗? 这是我的代码的一部分:

视图:

.
.
.
items: [{
  xtype: 'filefield',
  name: 'iconBmp',
  fieldLabel: this.i18nColIconBmp,
  enforceMaxLength : true,
  labelWidth: 100,
  msgTarget: 'side',
  anchor: '100%',
  buttonText: 'Exam'
}],
buttons: [{
  text: 'Upload',
  handler: function() {
    var form = this.up('form').getForm();
    if (form.isValid()) {
      form.submit({
        url: 'icon/upload',
        waitMsg: 'Uploading...',
        success: function(fp, o) {
          Ext.Msg.alert('Success', o.result.file + ' has been uploaded.');
        }
      });
    }
  }
}]

Java的:

@Path("icon")
public class CatIconRest {

  @POST
  @Path("/upload")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Response uploadFIle(
    @FormDataParam("file") InputStream uploadedInputStream,
    @FormDataParam("file") FormDataContentDisposition fileDetail) {

    String string = fileDetail.getFileName();
    System.out.println(string );
    // TODO:
    return null;
  }
}

问题是,我从来没有去过Java类,ExtJS形式不发送任何东西,我必须改变/添加?

如果你需要更多的代码,请问。

提前致谢!

编辑:我正在测试它与称为邮递员的铬扩展,这些是请求的配置:

邮差测试:

Accept: application/json
Content-type: multipart/form-data
Cache-Control: no-cache
Url: http://localhost/app/icon/upload
Method: POST
File: Mine.doc

我在项目中添加了一些jar,jersey-multipart-1.17.1.jar和mimepull-1.9.3.jar,但我无法用扩展名测试它,这就是我得到的结果:

A message body reader for Java class com.sun.jersey.core.header.FormDataContentDisposition, and Java type class com.sun.jersey.core.header.FormDataContentDisposition, and MIME media type multipart/form-data was not found.
The registered message body readers compatible with the MIME media type are:
*/* ->
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.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$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$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

问候。


显然在pom.xml中有一个依赖关系问题,并且配置错误,如果可以帮忙,我会把它留给其他人:

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public ServiceResponse uploadFIle(FormDataMultiPart form) {
    byte[] fileContents = form.getField("iconBmp").getValueAs(byte[].class);
    String uploadedfilename = form.getField("iconBmp").getContentDisposition().getFileName();
    String description = form.getField("description").getValue();
    String fileName = form.getField("fileName").getValue();
    //String id = form.getField("id").getValue();

    // TODO:
    //catIconBean.uploadIcon(fileContents);

    ServiceResponse sr = new ServiceResponse();
    sr.httpResponse = true;
    return sr;
}

问候。

链接地址: http://www.djcxy.com/p/91553.html

上一篇: File upload with ExtJS and Jersey

下一篇: Filter for limiting the file size on upload in Jersey