简体   繁体   中英

Django file upload with “application/octet-stream” content-type

I have a 3rd side service which making a POST request with file to my Django application.To success upload to Django application request must have 'multipart/form-data' content type but content type is 'octet-stream' in my case and Request.FILES is always empty. How can i receive file with 'octet-stream' content type in django?

request.content_type # is octet-stream 
form = UploadFileForm(request.POST, files=request.FILES)
file = form.cleaned_data[file_name]

If anybody stuck too I found a some solution. You can just read data as bytes and then save it to file

with open(file_name, 'wb') as output:
    output.write(request.read())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM