FileUpload with JAX-RS

后端 未结 5 1114
忘了有多久
忘了有多久 2020-11-30 05:08

I try to do file upload from a JavaScript client to a JAX-RS Java server.

I use the following REST upload function on my server:

@POST
@Produces(\'ap         


        
5条回答
  •  失恋的感觉
    2020-11-30 05:38

    There is no Jax-RS way to do this. Each server have their own extensions, all using Multi-part form submissions. For example, in CXF, the following will allow you to upload via a multipart form. (Attachment is a CXF specific extension)

    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(@Multipart(value = "vendor") String vendor,
            @Multipart(value = "uploadedFile") Attachment attr) {
    

    whereas the following is the same for Jersey (FormDataParam is a Jersey extension):

     @Consumes(MediaType.MULTIPART_FORM_DATA_TYPE)
     public String postForm(
             @DefaultValue("true") @FormDataParam("enabled") boolean enabled,
             @FormDataParam("data") FileData bean,
             @FormDataParam("file") InputStream file,
             @FormDataParam("file") FormDataContentDisposition fileDisposition) {
    

    (I've ignored the @Path, @POST and @Produces, and other non-relevant annotations.)

提交回复
热议问题