I obtained a upload uRL Programmatically from my deployed google app., however i keep getting the below response...what type of parameter am i missing?
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)
This is the code:
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() +"]" );