我想把一个csv文件从Android发送到Python AppEngine。我使用blobstoreapi,要发送文件,我使用MultipartEntity
、HttpPost
和{
因此,根据Blobstore API,您必须调用方法create_upload_url('/upload')
来生成上载文件的url,并将此url用作操作来上载文件。你可以读到here
我在干什么?我调用一个方法来创建这个url并将其返回到我的android应用程序。我用这个网址上传文件。在
生成的url格式如下:
myapp.appspot.com/_ah/upload/a-lot-of-numbers-and-letters/
基本上是这样的:
Android代码
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(mContext.getString("myapp.appspot.com/get_blobstore_url");
HttpResponse urlResponse = httpClient.execute(httpGet);
result = EntityUtils.toString(urlResponse.getEntity());
Uri fileUri = Uri.parse("file:///sdcard/dir/myfile.csv"); // Gets the Uri of the file in the sdcard
File file = new File(new URI(fileUri.toString())); // Extracts the file from the Uri
FileBody fileBody = new FileBody(file, "multipart/form-data");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("file", fileBody);
HttpPost httpPost = new HttpPost(result);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
response.getStatusLine();
AppEngine代码
^{pr2}$问题1
当我将文件发送到AppEngine返回的url时,这将自动调用服务器方法UploadHandler?因为这个方法中的日志消息没有显示,并且文件正在被插入,并且我在上传带有生成的url的文件时得到的响应是404错误,如果文件正在上载,为什么会出现这个错误?在
问题2
上传文件后,如何解析服务器中的csv文件并将文件中的所有数据插入到数据存储?在
谢谢。在
正确。
给我们看看你的服务器日志-你得到404的网址是什么?你从上传处理程序得到任何日志消息吗?
使用BlobReader API,并将打开的文件传递给python
csv
模块。相关问题 更多 >
编程相关推荐