0
我想從Flex上傳ActionScript中的大型圖像文件。文件上傳教程https://docs.djangoproject.com/en/dev/topics/http/file-uploads/處理來自表單的流式文件上傳,因此文件在request.FILE ['name']中轉換,但我不知道如何在actionscript中複製該文件。我想也對文件作爲POST參數傳遞,但我得到的錯誤:Actionscript(Flex)將流式傳輸上傳到Django
in handle_uploaded_file for chunk in f.chunks():
AttributeError: 'unicode' object has no attribute 'chunks'
它是錯誤的,我有隻使用request.FILE或者是它在我的動作問題我的Python代碼?沒有形式上傳文件的正確方法是什麼?這裏是我的ActionScript代碼:
var upload:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(UploadURL+"?var="+Math.random());
var sendVars:URLVariables = new URLVariables();
var header:URLRequestHeader = new URLRequestHeader("enctype", "multipart/form-data");
upload.dataFormat = URLLoaderDataFormat.BINARY;
upload.addEventListener(Event.COMPLETE, image.uploadedEvent);
sendVars.file = image.getBytearray(); // image is a JPEG encoded ByteArray
request.data = sendVars;
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
upload.load(request);
這裏是Django的部分:
def upload_file(request):
if request.method == 'POST':
handle_uploaded_file(request.POST.get('file'))
return HttpResponse()
def handle_uploaded_file(f):
destination = open('file.dat', 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
感謝