java - Jersey REST client - multipart creation - not from File object -


i guess there no other way creating filedatebodypart providing file object:

public filedatabodypart(string name, file fileentity) 

but in case have byte[] , don't want convert file , store on filesystem.

is there other way of generating multipart (while uploading file) array of byte, inputstream... in worst case using other client library?

update: here working code (but want use byte[] instead of file):

filedatabodypart filepart = new filedatabodypart("attachment", new file("c:/temp/test.txt")); multipart multipart = new formdatamultipart().bodypart(filepart); invocation.builder invocationbuilder = webtarget.request().accept(mediatype.application_json); response response = invocationbuilder         .buildpost(entity.entity(multipart, mediatype.multipart_form_data))         .invoke(); 

there's no other way filedatabodypart not accept file.

as workaround, might want create temporary file , delete once jvm exits:

byte[] bytes = {1, 2, 3};  file tempfile = file.createtempfile("filename", null); tempfile.deleteonexit();  fileoutputstream fos = new fileoutputstream(tempfile); fos.write(bytes); fos.close();  filedatabodypart filepart = new filedatabodypart("attachment", tempfile); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -