【发布时间】:2021-11-05 17:32:48
【问题描述】:
我尝试了很多方法将文件上传到服务器,但我总是得到响应{“detail”:“没有提交块文件”}。如何正确使用这个库?
我的一个尝试:
import requests
url = 'http://127.0.0.1:8000/chunked_upload/'
in_file = open("testfile.txt", "rb")
data = in_file.read()
response = requests.put(
url,
headers={
"Content-Range": f"bytes {0}-{9}/{10}"
},
data={"filename": "testfile"},
files={'file': data},
)
【问题讨论】:
-
尽量不要读取文件,直接使用文件句柄。
-
@KlausD。你的意思是这样试试:
files={'file': in_file }?如果是这样,很遗憾它不起作用 -
您也不能阅读该文件。顺便说一句,“它不起作用。”不是一个好的错误描述。
-
@KlausD。我照你说的做了,同样的错误
{"detail": "No chunk file was submitted"}
标签: python python-3.x django file-upload django-rest-framework