作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个第三端服务,它向我的 Django 应用程序发出带有文件的 POST 请求。要成功上传到 Django 应用程序,请求必须具有“multipart/form-data”内容类型,但内容类型在我的中为“octet-stream” case 和 Request.FILES 始终为空。我如何在 django 中接收具有“octet-stream”内容类型的文件?
request.content_type # is octet-stream
form = UploadFileForm(request.POST, files=request.FILES)
file = form.cleaned_data[file_name]
最佳答案
如果有人也卡住了,我找到了一些解决方案。您可以只读取字节数据,然后将其保存到文件
with open(file_name, 'wb') as output:
output.write(request.read())
关于python - Django 文件上传内容类型为 "application/octet-stream",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56380619/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!