Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android上传图像时,django中的request.FILES为空_Android_Python_Django_Image_Upload - Fatal编程技术网

从android上传图像时,django中的request.FILES为空

从android上传图像时,django中的request.FILES为空,android,python,django,image,upload,Android,Python,Django,Image,Upload,我想从android应用程序上传图像到djnago。这是我上传图像的android代码: public void upload(String filepath) throws IOException{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(SoberRequest.UPLOAD_IMAGE_URL); File file = new File

我想从android应用程序上传图像到djnago。这是我上传图像的android代码:

public void upload(String filepath) throws IOException{
     HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost(SoberRequest.UPLOAD_IMAGE_URL);
     File file = new File(filepath);
     MultipartEntityBuilder builder = MultipartEntityBuilder.create();        
     builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
     FileBody cbFile = new FileBody(file, "image/jpeg");
     builder.addPart("image", cbFile);
     HttpEntity mpEntity = builder.build();
     httppost.setEntity(mpEntity);
     httppost.setHeader("enctype", "multipart/form-data");
     HttpResponse response = httpclient.execute(httppost);
     HttpEntity entity = response.getEntity();
     ...
}
这是我获取和保存图像的django代码:

@csrf_exempt
def get_image(request):
    try:
        if request.method == "POST":
            destination_path = open("Images/filan.jpg", "wb+")
            print(request.FILES)
            image = request.FILES['image']
            destination_path.write(image)
            destination_path.close()
            json_data = {"status": SUCCESSFUL}
             return HttpResponse(json.dumps(json_data), mimetype=json_mimeType)
        else:
            json_data = {"status": ERROR}
            return HttpResponse(json.dumps(json_data), mimetype=json_mimeType)

打印request.FILES时,它为空:。django提出了这个多值错误验证。问题是什么?谢谢

您使用哪个版本的django?1)尝试检查您的请求。发布dict并确保没有任何类似于
cbFile
或类似的变量。2) 尝试更新django。旧版本中存在一些多值错误错误。3) 尝试在android端进行调试。它是否向服务器发送正确的数据?