Uploading JSON string besides File with file-transfer plugin to Java server


#1

I am trying to upload a file to my Java JAX-RS(Jersey) web service.

My method signature on the server side if anyone interested is like this;

public Response<ResponseUpload> upload(@FormDataParam("file") InputStream uploadedStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("question") String req_question, @Context HttpHeaders headers)

When I try to upload a file with Postman (Client for testing) using multipart/form-data, it is working properly. When I sniff it with Fiddler I see this;
POST http://localhost:8080/application/question/post HTTP/1.1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryT79BovKwL6ObBceu
Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4
------WebKitFormBoundaryT79BovKwL6ObBceu
Content-Disposition: form-data; name="file"; filename="PARS.png"
Content-Type: image/png
[HERE SOME STRANGE RAW BINARY DATA]
------WebKitFormBoundaryT79BovKwL6ObBceu
Content-Disposition: form-data; name="question"
{"title": "This is title!",  "fk_field_id":1}
------WebKitFormBoundaryT79BovKwL6ObBceu--

But when I try to achieve the same upload with Angular my request look like this;

POST http://localhost:8080/application/question/post HTTP/1.1
Content-Type: multipart/form-data
Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4
/Exif  II*  [SOME STRANGE RAW BINARY DATA]

Here is my code in ionic, cut for clarity;

let options: FileUploadOptions =
 {
   fileKey: 'file',
   headers: headers,
   params: {"title": "This is title!",  "fk_field_id":1} // Actually I am getting this from yet to shorten code I moved it
};
path = {MY ENDPOINT IN SERVER}
filePath = file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1497313256081.jpg  // Getting as method param
fileTransfer.upload(filePath, path, options).then(things => {
 //Some console.log
});

How can I achieve POSTMAN like structure inside Ionic? Anyone has knowledge…