java - Restlet & MULTIPART_FORM_DATA or another way to put files on Google App Engine via Restlet -
i tried receive files via restlet gets complete multipart_form_data. how can extract specific file?
i found code-blocks types of them not available... restlet: how process multipart/form-data requests?
diskfileitemfactory factory = new diskfileitemfactory(); factory.setsizethreshold(1000240); // 2/ create new file upload handler restletfileupload upload = new restletfileupload(factory);
my current code:
@put public void handleupload(representation entity) { if (entity !=null) { if (mediatype.multipart_form_data.equals(entity.getmediatype(), true)) { request restletrequest = getrequest(); response restletresponse = getresponse(); httpservletrequest servletrequest = servletutils.getrequest(restletrequest); httpservletresponse servletresponse = servletutils.getresponse(restletresponse); try { upload2(restletrequest, entity); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } public void upload2(request req, representation entity) throws ioexception { ... gcsoutputchannel outputchannel = gcsservice.createorreplace(filename, gcsfileoptions.getdefaultinstance()); objectoutputstream oout = new objectoutputstream(channels.newoutputstream(outputchannel)); copy(entity.getstream(), oout); oout.close();
after storing method have , want store content name "picture":
��z------webkitformboundarysovzwkpqyqw7ditu content-disposition: form-data; name="picture"; filename="_mg_4369.jpg" content-type: image/jpeg ����*exifii*
as far read parsing of multipart form data isn’t supported yet? there must solution send files via restlet
i tried rest-calls via postman chrome. on multiparts support files. possible solution send image raw-text?
you need add exception
handling , deal inputstream
, potentially clean of temp files (see diskfileitemfactory
docs) basics follows, when using org.restlet.ext.fileupload library.
@put public void handleupload(representation entity) { list<fileitem> items = new restletfileupload(new diskfileitemfactory()) .parserepresentation(representation); (fileitem item : items) { if (!item.isformfield()) { mediatype type = mediatype.valueof(item.getcontenttype()); inputstream inputstream = item.getinputstream(); } } }
for gae solution try replacing diskfileitemfactory
gwtupload.server.memoryfileitemfactory
.
Comments
Post a Comment