Uploading File Via Form Into Gae From Android
I have an app on GAE at: http://1.myawesomecity.appspot.com/ FIXED: HttpPost post = new HttpPost('http://1.myawesomecity.appspot.com/'); http_client
Solution 1:
Uploading file to a blobstore on GAE is a two step process:
first you need to get a proper URL where to POST your data, usually people use something like "/bloburl" handler for that purpose
when you have blob upload URL, you use it in your request.
the file you send does not go as
NameValuePair, it's supposed to go as aMultiPartEntity.
here's the code that works (you'll need apache http library for MultiPartEntry support):
DefaultHttpClienthttp_client=newDefaultHttpClient();
HttpGethttp_get=newHttpGet(Config.BASE_URL + "bloburl");
HttpResponseresponse= http_client.execute(http_get);
BufferedReaderreader=newBufferedReader(newInputStreamReader(response.getEntity().getContent()));
Stringfirst_line= reader.readLine();
Log.w(TAG, "blob_url: " + first_line);
HttpPostpost=newHttpPost(first_line);
http_client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
MultipartEntityentity=newMultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
mime_type = "application/zip";
Filefile=newFile( context.getFilesDir(), filename );
entity.addPart( "file", newFileBody( file, mime_type));
post.setEntity( entity );
Stringresult= EntityUtils.toString( http_client.execute(post).getEntity(), "UTF-8");
Log.i(TAG, result);
Post a Comment for "Uploading File Via Form Into Gae From Android"