how to upload a file from android app to google ap

2019-07-22 12:22发布

I have a JSP file where the form field will uploads a file to Google app engine, the below code shows it,

 <form name="myform" id="myform" action="<%= blobstoreService.createUploadUrl("/adminupload",UploadOptions.Builder.withGoogleStorageBucketName("sampleapp")) %>" method="post" enctype="multipart/form-data">

as i wrote this program with jsp and servlet i need to provide the same process in android app. If my GAE path is say like this http://sampleapp.appspot.com/Upload.jsp how can i provide this link in the form action property of an android app. As i don't have idea about android app. Kindly suggest me what to provide in android app form property so that from the app a file can be uploaded.

Kindly tell me whether it is possible in android form to give url path like this,

http://sampleapp.appspot.com/uploadservlet

so that the android app will upload the file in the GAE sampleapp.appspot.com

1条回答
聊天终结者
2楼-- · 2019-07-22 13:03

Yes it is. Use an HttpPost object by passing your server URL in the constructor.

HttpPost request = new HttpPost(urlString);

[EDIT]: Just noticed you used multipart entries. I'd suggest you do something of the sort explained in this tutorial.

When you pass the url as a parameter you're telling Java the destination for your request. So your request must then contain your file data (written in any way you wish DataOutputStream or any other way) and then you must execute it using an HttpClient object.

Further, from the GAE pages on JSP you can see that every new <form action="/handleName" method="methodName"> you add will result in:

.. a new URL, /handleName, to be handled by a new servlet class...

查看更多
登录 后发表回答