File upload using Jersey: FormDataContentDisposition is null

I am trying to implement file upload using Jersey, so I followed this example: http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/ which worked well with the HTML page. Now I adapted it to my application, here is the code:

  public Response uploadFile(
    @FormDataParam("file") InputStream uploadedInputStream,
    @FormDataParam("file") FormDataContentDisposition fileDetail)
    throws IOException {

Response.Status respStatus = Response.Status.OK;

if (fileDetail == null) {
    respStatus = Response.Status.INTERNAL_SERVER_ERROR;
} else {
    try {
    initPath();
    if (fileDetail.getSize() > OntoWebStudioUtil
        .getUploadFileLimit()) {
        respStatus = Response.Status.NOT_ACCEPTABLE;
        return Response.status(respStatus).build();
    }

    writeToFile(uploadedInputStream, tempDirectory);
    } catch (Exception e) {
    respStatus = Response.Status.INTERNAL_SERVER_ERROR;
    e.printStackTrace();
    }
}
return Response.status(respStatus).build();
}

But with a debug view, as soon as I uploaded my photo and hit the submit button, and then go here, uploadedInputStream and fileDetail are null. So I canโ€™t do anything ... I am new to servlet and then REST, so please be lenient.

Thank.

+4
source share
1

, : , , FormDataParameter ( "myForm" ), , HTML- (name = "myForm" )

,

@FormDataParam("myForm") InputStream uploadedInputStream,
@FormDataParam("myform") FormDataContentDisposition fileDetail)

    <form action=".../rest/fileupload" method="post" enctype="multipart/form-data">
   <p>
    Select a file : <input type="file" name="myForm"/>
   </p>
   <input type="submit" value="Upload It" />
</form>

, , :)

+17

Source: https://habr.com/ru/post/1536595/


All Articles