how to upload image to Jersey RestApi Server
mica83 opened this issue · comments
Hi, i have to upload image , taked from camera, to Jersey RestApi Server.
An example of "request header" that works fine is:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarygSU5m5Vs01uM28re
Content-Length: 156
Source message
POST /Api/v1/upload/images HTTP/1.1
HOST: localhost:8080
content-type: multipart/form-data; boundary=----WebKitFormBoundarygSU5m5Vs01uM28re
cookie: JSESSIONID=F35F867DD509BBCCF641FC3FF9418F29
content-length: 156
------WebKitFormBoundarygSU5m5Vs01uM28re
Content-Disposition: form-data; name="fileUpload"
[object Object]
------WebKitFormBoundarygSU5m5Vs01uM28re--
How can I do this with RESTe lib?
How is your server expecting the image? Are you base64encoding it or trying to send it raw?
I think raw, (look attachment)
If can help you, this is annotation of API method:
@POST
@Path("/upload/images")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadImageFile(
@FormDataParam("uploadFile") InputStream fileInputStream,
@FormDataParam("uploadFile") FormDataContentDisposition fileFormDataContentDisposition) {
ok -- you have the ability override headers for a specific method -- so for the method you're configuring in the RESTe config, specify the headers for that method so their are multipart etc -- it should then work
can you give me an example ?
within your method, have a "headers" property that will be like:
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
which will override the header being specified globally.