从blobstore上传中获取500错误(缺少;)

时间:2014-04-09 09:35:48

标签: forms google-app-engine http blobstore google-http-client

我想跳过将上传URL发送到客户端的部分,并从后端直接上传到blobstore。我使用this发送多部分请求,但我得到:

<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing/_ah/upload/ahB0NTIzNjU4OTY1ODk1Njg5ciILEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YgICAgICAiAs    M. Reason:
<pre>    Missing ';'</pre></p><h3>Caused by:</h3>    <pre>javax.mail.internet.ParseException: Missing ';'
at javax.mail.internet.ParameterList.&lt;init&gt;(ParameterList.java:135)
at javax.mail.internet.ContentType.&lt;init&gt;(ContentType.java:72)
at javax.mail.internet.MimeMultipart.&lt;init&gt;(MimeMultipart.java:98)
at com.google.apphosting.utils.servlet.MultipartMimeUtils.parseMultipartRequest(MultipartMimeUtils.java:41)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.handleUpload(UploadBlobServlet.java:173)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.access$000(UploadBlobServlet.java:71)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet$1.run(UploadBlobServlet.java:117)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.doPost(UploadBlobServlet.java:114)

这是发送的数据:

--__END_OF_PART__
Content-Type: image/bmp
content-transfer-encoding: binary
content-disposition: form-data; name="file"

[binary string here]
--__END_OF_PART__--

这些是标题:

accept-encoding: gzip,
content-type: multipart/form-data; boundary=__END_OF_PART__

这是代码:

BlobstoreService service = BlobstoreServiceFactory.getBlobstoreService();
String url = service.createUploadUrl("/upload");

HttpRequestFactory factory = UrlFetchTransport.getDefaultInstance().createRequestFactory();


MultipartFormContent content = new MultipartFormContent();
content.addPart(new MultipartFormContent.Part(
            "file",
            new InputStreamContent("image/bmp", 
                    new ByteArrayInputStream(Base64.decodeBase64(data)))));

content.writeTo(System.out);

HttpRequest request = factory.buildPostRequest(new GenericUrl(new URL(url)), content);
request.getHeaders().setContentType(content.getMediaType().build());
request.execute();

1 个答案:

答案 0 :(得分:0)

docs所述,多部分正文必须为multipart/form-data,输入类型为&#34; file&#34;,它会生成Content-Disposition标题为&#34;文件名&#34;部分:

Content-Disposition: form-data; name="myFile"; filename="imagename.bmp"

使用HttpClient时,它应该是like this