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

我需要一些帮助。
我一直在开发一个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。根据规范,这是无效的。

Java-搜索字符串数组中的字符串 - java

在Java中,我们是否有任何方法可以发现特定字符串是字符串数组的一部分。我可以避免出现一个循环。例如String [] array = {"AA","BB","CC" }; string x = "BB" 我想要一个if (some condition to tell wheth…

Java-如何将此字符串转换为日期? - java

我从服务器收到此消息,我不明白T和Z的含义,2012-08-24T09:59:59Z将此字符串转换为Date对象的正确SimpleDateFormat模式是什么? java大神给出的解决方案 这是ISO 8601标准。您可以使用SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM…

Java Double与BigDecimal - java

我正在查看一些使用双精度变量来存储(360-359.9998779296875)结果为0.0001220703125的代码。 double变量将其存储为-1.220703125E-4。当我使用BigDecimal时,其存储为0.0001220703125。为什么将它双重存储为-1.220703125E-4? 参考方案 我不会在这里提及精度问题,而只会提及数字…

Java:线程池如何将线程映射到可运行对象 - java

试图绕过Java并发问题,并且很难理解线程池,线程以及它们正在执行的可运行“任务”之间的关系。如果我创建一个有10个线程的线程池,那么我是否必须将相同的任务传递给池中的每个线程,或者池化的线程实际上只是与任务无关的“工人无人机”可用于执行任何任务?无论哪种方式,Executor / ExecutorService如何将正确的任务分配给正确的线程? 参考方案 …

JAVA:字节码和二进制有什么区别? - java

java字节代码(已编译的语言,也称为目标代码)与机器代码(当前计算机的本机代码)之间有什么区别?我读过一些书,他们将字节码称为二进制指令,但我不知道为什么。 参考方案 字节码是独立于平台的,在Windows中运行的编译器编译的字节码仍将在linux / unix / mac中运行。机器代码是特定于平台的,如果在Windows x86中编译,则它将仅在Win…