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 view this discussion on the web visit
https://groups.google.com/d/msg/google-appengine-java/-/GKmkwO4-_mwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.