我正在尝试将带有apache cordova文件传输插件的图片发送到基于django的后端。当我通过后端的文件传输插件提交图片时,它不会识别任何参数。
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://127.0.0.1:8000/declare/"), win, fail, options);
}
reqeust.FILES,request.POST,request.GET一切都是空字典。当我将网址提交到hookbin时,它似乎可以识别所有内容。什么是django保持请求.FILES等空的原因可能是什么?
@csrf_exempt
def declare(request):
me = User.objects.get(username='test')
response = JsonResponse({'success': "ok"})
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
response["Access-Control-Max-Age"] = "1000"
response["Access-Control-Allow-Headers"] = "*"
return response
答案 0 :(得分:0)
看起来cordova插件默认使用分块传输。
chunkedMode: Whether to upload the data in chunked streaming mode. Defaults to true. (Boolean)
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/
你可能想要禁用它或使用库来帮助在服务器端上传上传,例如https://github.com/juliomalegria/django-chunked-upload