将文件从Android App上传到Flask Server

时间:2016-09-09 08:31:07

标签: android python file http flask

我尝试使用从之前的StackOverfow问题获得的逻辑将文件从Android应用程序上传到Flask服务器,但在Flask端,request.values为空,内容长度也有没有价值。

Android代码

    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
                System.out.println("Sending Message");
                String url = "http://localhost:5005/pin/123/upload";
                File file = new File(audioRecorder.getCurrentAudioPath());
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost post = new HttpPost(url);

                    InputStreamEntity entity = new InputStreamEntity( new FileInputStream(file), -1);
                    entity.setContentType("binary/octet-stream");
                    entity.setContentEncoding("binary");
                    entity.setChunked(true);
                    post.setEntity(entity);
                    HttpResponse resp = httpclient.execute(post);
                    System.out.println(resp.getStatusLine());
                }

                catch(Exception e)
                {
                    e.printStackTrace();
                 // System.err.println(e.printStackTrace());
                }

Flask Code

def uploadFiles(pin):
    print request.headers
    print str(request.values)

返回

Transfer-Encoding: chunked
Content-Length:
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Connection: Keep-Alive
Content-Encoding: binary
Host: localhost:5005
Content-Type: binary/octet-stream

CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([])])

0 个答案:

没有答案