I just switch to GAE sdk 1.5.2. Now I get error 411, "Length required"
from GAE since this version of GAE requires Content-Length on POSTs.
The problem seems to originate from HttpClient since there's no
problem with posts from RESTlet. However, I need HttpClient for
multipart file upload. Wireshark shows that indeed Content-Length is
not included in headers. Trying to set content-length manually is not
allowed. Anyone else run across this?
Here's the HttpClient code,
HttpClient httpclient = new DefaultHttpClient();
MultipartEntity reqEntity = new MultipartEntity();
try {
reqEntity.addPart("title", new
StringBody( dataMap.get("title").toString(),
Charset.forName("UTF-8")));
reqEntity.addPart("numPages", new
StringBody( dataMap.get("numPages").toString(),
Charset.forName("UTF-8")));
// Get stream from file
File file = new File(dataMap.get("cover").toString());
FileInputStream fileStream = new FileInputStream( file );
InputStreamBody streamBody = new InputStreamBody( fileStream,
"image/jpeg,image/png", file.getName());
reqEntity.addPart("cover", streamBody);
HttpPost httppost = new
HttpPost(Settings.getInstance().getHost() + "/books");
httppost.addHeader("Accept", "application/json");
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
EntityUtils.consume(resEntity); // Not sure this is needed
here?
if (response.getStatusLine().getStatusCode() == 200) {
logger.log(Level.INFO, "book added: title - " +
dataMap.get("title"));
} else{
logger.log(Level.INFO, "book add failed: title
- " +
dataMap.get("title") + " code, message - " +
response.getStatusLine().getStatusCode() + ", " +
response.getStatusLine().getReasonPhrase());
}
Note - this worked fine in earlier version of GAE where it wasn't
required to get Content-Length
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
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?hl=en.