【发布时间】:2016-12-22 21:51:17
【问题描述】:
我从部署的谷歌应用程序中以编程方式获得了上传 uRL。但是我不断收到以下响应...我缺少什么类型的参数?
Bad content type. Please use multipart.
2016-08-16 09:25:34 ERROR PayitWebClientApp:207 - 400 Bad Request
Bad content type. Please use multipart.
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
at com.vanitysoft.payit.PayitInvokeAuthApp.generateUploadUr(PayitInvokeAuthApp.java:198)
at com.vanitysoft.payit.PayitInvokeAuthApp.main(PayitInvokeAuthApp.java:217)
这是代码:
MultipartContent content = new MultipartContent().setMediaType(
new HttpMediaType("multipart/form-data")
.setParameter("boundary", "__END_OF_PART__"));
FileContent fileContent = new FileContent(
"multipart/related", file);
MultipartContent.Part part = new MultipartContent.Part(fileContent);
part.setHeaders(new HttpHeaders().set(
"Content-Disposition",
String.format("form-data; name=\"content\"; filename=\"%s\"", file.getName())));
content.addPart(part);
httpRequest = httpRequestFactory.buildPostRequest(new GenericUrl(uploadItem.getUploadUrl()) ,fileContent);
LOGGER.info("upload...[" + uploadItem.getUploadUrl() +"]");
httpResponse = httpRequest.execute();
LOGGER.info("Upload complete");
Assert.isTrue(httpResponse.getStatusCode() == 200, IOUtils.toString(httpResponse.getContent()));
LOGGER.info( "Success[" + httpResponse.getContent() +"]" );
【问题讨论】:
标签: google-app-engine blobstore