简体   繁体   English

使用Errai进行多部分表格上传

[英]Multi-part form upload with Errai

I'm trying to do a file upload for my Errai app, however I'm getting this error: 我正在尝试为我的Errai应用上传文件,但是却出现此错误:

[INFO] DEBUG [SynchronousDispatcher] PathInfo: /blob
[INFO] WARN [ExceptionHandler] Failed executing GET /blob
[INFO] org.jboss.resteasy.spi.NotAcceptableException: No match for accept header
[INFO]  at org.jboss.resteasy.core.registry.Segment.match(Segment.java:119)
[INFO]  at org.jboss.resteasy.core.registry.PathParamSegment.matchPattern(PathParamSegment.java:200)
[INFO]  at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:339)

The Errai service looks like this: Errai服务看起来像这样:

@Path("blob")
public interface BlobService {
    @GET
    @Produces(MediaType.TEXT_PLAIN) 
    String getBlobStoreUploadUrl(); // return "/blob/upload"

    @GET
    @Path("/{id}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON) 
    Picture getPicture(@PathParam("id") String id);

    @POST 
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    void uploadPicture();
}

Now, upload is triggered this way: 现在,上传是通过以下方式触发的:

submitButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent e) {
                blobService.call(new RemoteCallback<String>() {
                    @Override
                    public void callback(String response) {
                        uploadForm.setAction(response);
                        uploadForm.submit();
                        uploadForm.reset();
                    }
                }).getBlobStoreUploadUrl();
            }
        });

From what it seems there a discrepancy on how I did file upload. 从表面上看,我的文件上传方式存在差异。 The idea here is just to upload the file selected in the usual upload form to the uploadPicture method. 这里的想法只是将在通常的上传表单中选择的文件上传到uploadPicture方法。

What could be wrong in the way I coded the upload service? 我编码上传服务的方式可能出什么问题?

have you set the mime type on the form? 您在表格上设置了MIME类型吗? like so 像这样

<form enctype='multipart/form-data'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM