javaee-esprit / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

How to use MultipartContent submit form data with file? #786

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-api-java-client 1.15.0-rc

Java environment Java 6, Android 2.3

The code :
   UrlEncodedContent urlEncodedContent = new UrlEncodedContent(params);
   FileContent fileContent = new FileContent("application/octet-tream", new File("/mnt/sdcard/images.jpg"));
   MultipartContent multipartContent = new MultipartContent();
   multipartContent.addPart(new Part(urlEncodedContent));
   multipartContent.addPart(new Part(fileContent));

when I use 
AndroidHttp.newCompatibleTransport().createRequestFactory().buildPostRequest(new
 GenericUrl("url"), multipartContent).execute();
the web server can not receive the params and files .

MultipartContent output :
   --__END_OF_PART__
Content-Length: 17
Content-Type: application/x-www-form-urlencoded; charset=UTF-8; 
content-disposition=ee
content-transfer-encoding: binary

a=b&aa=bb&aaa=bbb
--__END_OF_PART__
Content-Length: 4
Content-Type: application/octet-stream
content-transfer-encoding: binary

cccc
--__END_OF_PART__--

After check, I found that different from web form submission . 

Who can help me to solve this problem? Thank you ~

Original issue reported on code.google.com by zhongwe...@gmail.com on 24 May 2013 at 3:57