rest - Call a Upload API in Java -


there 1 post api in azkaban upload zip file. able upload using curl have given in documentation.

curl -k -i -h "content-type: multipart/mixed" -x post --form 'session.id=47cb9240-f8fe-46f9-9cba-1c1a293a0cf3' --form 'ajax=upload' --form 'file=@atest.zip;type=application/zip' --form 'project=aaaa;type=plain' http://localhost:8081/manager 

http://azkaban.github.io/azkaban/docs/2.5/#api-upload-a-project-zip

but want call same api in java. can me how in java?

you need use apache httpcomponents framework.

create httpclient, httppost request, , multipart entity, , execute request. sample below:

httpclient httpclient = httpclientbuilder.create().setdefaultconnectionconfig(config).build(); httppost httppost = new httppost(url);  multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible);  // add parts form here builder.addpart("<param name>", <part>);  // if need upload file file uploadpkg = new file(pathtoupload); filebody fbody = new filebody(uploadpkg); builder.addpart("file", fbody);  httpentity entity = builder.build(); httppost.setentity(entity);  httpresponse httpresponse =  httpclient.execute(httppost);  system.out.println(entityutils.tostring(httpresponse.getentity())); 

hope helps.


Popular posts from this blog