当从Android

时间:2018-01-14 15:11:52

标签: android python django retrofit

我正在尝试制作一个Android应用程序,使用Retrofit框架将拍摄的照片发布到django服务器。

我的机器人部分:

private void uploadFile(Uri filePath) {

        String path = getRealPathFromURI(filePath);

        File originalFile = new File(String.valueOf(path));

        RequestBody filePart = RequestBody.create(MediaType.parse("multipart/form-data"),originalFile);

        MultipartBody.Part file = MultipartBody.Part.createFormData("upload", path, filePart);

        ApiRequestsService.UploadFile(this, new OnApiResponseListener() {
            @Override
            public void onApiComplete(Object object) {
                RetrofitResponse response = (RetrofitResponse) object;
                Toast.makeText(context, response.success, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onApiError(Exception e) {
            }
        }, "Loading...", file);
    }

@Multipart
@POST("/uploadImage/")
Call<ResponseBody> uploadFile(@Part("upload") MultipartBody.Part file);

在服务器端的views.py文件中,我有:

def uploadImage(request):
    # check to see if this is a post request
    if request.method == "POST":

        print request.FILES
        if 'upload' in request.FILES: 
            print "success!"
            upload = request.FILES['upload']
        else:
            print "something's wrong"

我得到的回应是:

[14/Jan/2018 15:55:24] "POST /uploadImage/ HTTP/1.1" 200 47
MultiValueDict: {}

任何帮助将不胜感激。

0 个答案:

没有答案