繁体   English   中英

使用Android应用程序将文件上传到我的Google API项目

[英]Using an android application to upload a file to my Google API project

我需要一些帮助。 我一直在开发一个Android游戏,其中将有关您进度的一些信息发送到服务器。 另外,您需要记录您的声音,游戏将发送到我的Google服务器上的blobstore。

我设法使用Jsoup将表单上传到我的数据存储区。

我的问题是我一直试图以各种方式将内容上传到我所做的文件上传应用程序。 没有成功

这是我的Google APP代码(python)。 它可以在我的浏览器上完美运行,并且可以将文件上传到我的Blobstore。 基本上,这是一个HTTP文件POST表单

import os
import urllib

from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

class MainHandler(webapp.RequestHandler):
    def get(self):
        upload_url = blobstore.create_upload_url('/upload')
        self.response.out.write('<html><body>')
        self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
        self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit" name="submit" value="Submit"> </form></body></html>""")

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get_uploads('file')
        blob_info = upload_files[0]
        self.response.out.write('success!')
        #self.redirect('/')


app= webapp.WSGIApplication(
          [('/', MainHandler),
           ('/upload', UploadHandler),
          ], debug=True)

这是我一直试图用来上传东西的代码。 此代码在我的Andorid手机上运行。

public static void sendF(File file)
{

    if (file.exists())
    {
        Log.e("msg", "exists");
    }
    else
    {
        Log.e("msg", "does not exists");
    }
    String url = "http://MYAPP.appspot.com/";
    HttpClient httpclient = AndroidHttpClient.newInstance("MyGame");



    HttpPost httpost = new HttpPost(url);
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("file", new FileBody(file));
    httpost.setEntity(entity);
    HttpResponse response;
    try {
        response = httpclient.execute(httpost);
        Log.e("internet", EntityUtils.toString(response.getEntity()));
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

问题是:我不断得到这个

05-29 17:10:52.369: E/internet(1720):   <h1>405 Method Not Allowed</h1>
05-29 17:10:52.369: E/internet(1720):   The method POST is not allowed for this resource. <br /><br />

(尽管我可以通过网络浏览器使用它。有人可以帮助我吗?(对不起,如果我不清楚)

我发现JSoup有一个错误,无法正确处理重定向。 而不是将请求传输到GET,而是将其保留为POST。 根据规范,这是无效的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM