java - Sending a class object to a multipart-form-data-expected web service -


this web service's declaration

@post @path("/upload") @consumes(mediatype.multipart_form_data) @produces("application/json") public devicedbuploadresponse upload(@formdataparam("file1") inputstream file1,  @formdataparam("file2") inputstream file2, @formdataparam("name1") string filename1, @formdataparam("name2") string filename2, @formdataparam("id") string id) 

my web service call

var fd=new formdata(); fd.append("id",id); /* lines of code here */  $.ajax({          url: 'http://localhost:8080/linterm2m/webapi/m2m/upload',          data: fd,          processdata: false,          contenttype: false,          type: 'post'        }); 

everything works far. required receive data (filename , id) through request object, like:

public class request{     string id;     string filename1;     string filename2; } 

but doubt can fulfilled because of multipart-form-data consuming type. need enlightenment , solution.

composing multipart/form-data different content-type on each parts javascript (or angular)

i try following answer in question , works.

fd.append('whole', new blob([json.stringify({         id: id,         name1:file1.name,         name2:file2.name,     })], {         type: "application/json"     })); 

the request class mentioned. name1,name2 part not needed want test object various attributes. appreciation naman's formdatacontentdisposition.


Popular posts from this blog