Hi Dick, Your suggestions did the trick - thanks ever so much!
Sincerely, Rune Nielsen On Oct 27, 9:39 am, Dick Larsson <dicklars...@gmail.com> wrote: > In method uploadAvatarImage you call for the inputStream before you > have sent your bytes to the server. > Please try this instead > os.flush(); > os.close(); > InputStream is = servletConnection.getInputStream(); > > Next thing, in your servlet. > You should use InputStream instead of Reader since you are dealing > with bytes > > InputStream reader = request.getInputStream(); > byte[] imageBytes = > org.apache.commons.io.IOUtils.toByteArray(reader); > > Hope it helps > Best regards > /Dick Larsson > > On 24 Okt, 16:17, Rune Nielsen <runeniel...@gmail.com> wrote: > > > > > > > > > Hi, > > > I'm trying to upload an image to store in the Blobstore, but I'm having > > trouble streaming it to my servlet as a byte array. > > > Here's the code for the client method streaming the byte array to the > > servlet - it's using the Commons IO: > > > public void uploadAvatarImage(byte[] imageBytes) { > > try { > > URL myURL = new > > URL("http://myapp.appspot.com/SetAvatar?globalId=1"); > > URLConnection servletConnection = myURL.openConnection(); > > > servletConnection.setRequestProperty("Content-Type", > > "application/octet-stream"); > > > servletConnection.setDoOutput(true); > > servletConnection.setDoInput(true); > > > OutputStream os = servletConnection.getOutputStream(); > > InputStream is = servletConnection.getInputStream(); > > > IOUtils.write(imageBytes, os); > > > os.flush(); > > os.close(); > > > BufferedReader in = new BufferedReader(new > > InputStreamReader(is)); > > String inputLine; > > > while ((inputLine = in.readLine()) != null) { > > System.out.println(inputLine); > > } > > > in.close(); > > } > > catch (Exception e) { > > System.out.println(e); > > } > > } > > > Here's the code for the doPost method of my servlet: > > > @Override > > public void doPost(HttpServletRequest request, HttpServletResponse > > response) throws IOException, ServletException { > > BufferedReader reader = request.getReader(); > > byte[] imageBytes = IOUtils.toByteArray(reader); > > > PrintWriter outputWriter = response.getWriter(); > > > int len = ; > > outputWriter.println("Content type is: " + request.getContentType() > > + " - length is: " + request.getContentLength()); > > outputWriter.println("Bytes: " + imageBytes.length); > > > outputWriter.close(); > > } > > > The output from the servlet is: > > > Content type is: application/octet-stream - length is 0 > > Bytes: 0 > > > Everything looks good on the client side and the size of the byte array on > > the client size is about 300kb. But for some reason there's no available > > bytes on the server side. Any ideas why? I've tried just about everything, > > but to no avail. > > > Thanks in advance for any hints! > > > Sincerely, > > Rune Nielsen -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.