Using apache fileupload in gae

I am using Apache Commons FileUpload in a Java side application that has an html form with fields:

  • Assigned feed to be populated with the destination mailbox email address
  • Message text with sender message
  • A <input type = file ... field for loading photos. I can get the downloaded file (as a stream), but how

This is the application I want to download on GAE. I can get the downloaded file (as a stream using org.apache.commons.fileupload.FileItemStream ).

I want to get input text fields too (i.e. 1) and 2)) - filled in by the application user)

I want to access them using org.apache.commons.fileupload.FileItem , but I get java.rmi.server.UID is a restricted class

+6
source share
2 answers

You must use FileItemIterator Apache Commons FileUpload .

 import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.servlet.ServletFileUpload; import java.io.InputStream; .. public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { ServletFileUpload upload = new ServletFileUpload(); res.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(req); while (iterator.hasNext()) { FileItemStream item = iterator.next(); String name = item.getFieldName(); InputStream stream = item.openStream(); if (item.isFormField()) { //regular form field resp.getWriter().println(("Form:" + name + " : " + Streams.asString(stream)); } else { //fileform field resp.getWriter().println(("File:" +name + " : " + item.getName()); } } } catch (Exception ex) { throw new ServletException(ex); } } 
+10
source

Take a look at this: Google App Engine and FileUpload

You cannot write directly to the file system in GAE, but look at GAEVFS , which uses data storage and memcache to emulate the file system.

+1
source

Source: https://habr.com/ru/post/886380/


All Articles