0

I have this http request to upload a image (application/octet-stream). I don't know how to receive this application/octet-stream from server side (java spring servlet). I try to do this

request.getPart("ax_file_input");

but I get null.

Here is the request looks like:

Header:

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4,ja;q=0.2
Connection:keep-alive
Content-Length:27530
Content-Type:multipart/form-data; boundary=----       WebKitFormBoundarymuhts7ls9NLoqkUW 

Request Payload:

------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-max-file-size"

10485760
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-thumbPostfix"

_thumb  

------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-thumbHeight"

0
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-thumbWidth"

0 
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-file-size"

25896
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-file-name"

avatar3.png 
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax_file_input"; filename="blob"
Content-Type: application/octet-stream


------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-start-byte"

0
------WebKitFormBoundarymuhts7ls9NLoqkUW
Content-Disposition: form-data; name="ax-file-md5"


------WebKitFormBoundarymuhts7ls9NLoqkUW--
John
  • 791
  • 2
  • 7
  • 25
  • Possible duplicate of [How to upload files to server using JSP/Servlet?](http://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet) – worpet Sep 23 '16 at 13:59

1 Answers1

1

Apache commons fileupload can be used to parse a multipart request (which is what you'll need to upload a file).

There is an example here: http://codingitforward.blogspot.com/2010/01/java-upload-servlet.html

slambeth
  • 887
  • 5
  • 17