Found the problem.
InputStreamBody streamBody = new InputStreamBody( fileStream, "image/
jpeg,image/png", file.getName());
If I use a stream, the length is unknown, the content chunked and
HttpClient leaves out Content-Length.
switched to,
File file = new File(dataMap.get(orientation).toString());
reqEntity.addPart(orientation, new FileBody(file, "image/
jpeg,image/png"));
The length is known and HttpClient can set it.
Still wondering if/when the per entity size for post will be increased
from 1M
On Aug 29, 1:54 pm, mikaye <[email protected]> wrote:
> 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.