Note that there are some explanatory texts on larger screens.

plurals
  1. POApp Engine and commons FileUpload
    text
    copied!<p>I'm sending a message built with google's protocol buffer from and android device using this code:</p> <pre><code>// Set up the HttpClient HttpClient client = new DefaultHttpClient(); String url = "http://192.168.2.103:8888/sdroidmarshal"; HttpPost postRequest = new HttpPost(url); // Create the content for the message AbstractContentBody[] parts = new AbstractContentBody[1]; InputStream ins = new ByteArrayInputStream(offers.build().toByteArray()); parts[0] = new InputStreamBody(ins, "sdroidmsg"); // Add the content to the message MultipartEntity requestContent = new MultipartEntity(); requestContent.addPart("message", parts[0]); // Send! postRequest.setEntity(requestContent); client.execute(postRequest); try { ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = client.execute(postRequest, responseHandler); } catch (Throwable t) { } </code></pre> <p>Eventually this code will actually be sending more than one part...</p> <p>I have a servlet running on Google's app engine that receives this post request and at the moment only has the following code:</p> <pre><code> protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doPost(req, resp); try { ServletFileUpload upload = new ServletFileUpload(); resp.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(req); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); if (item.isFormField()) { log.warning("Got a form field: " + item.getFieldName()); } else { log.warning("Got an uploaded file: " + item.getFieldName() + ", name = " + item.getName()); } } } catch (Exception ex) { throw new ServletException(ex); } } </code></pre> <p>Obviously the server doesn't do very much right now! But I have noticed that it seems to receive two parts both called "message" and file "sdroidmsg", which I really don't understand. Surely it should only receive this once? I thought perhaps that sdroidmsg might be being split into two part because of size, but that is a complete guess, I don't really know the inner working of what's happening behind the scenes. Could anyway explain why this is happening? I can post more code if required.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload