【发布时间】:2021-06-07 12:04:58
【问题描述】:
我正在尝试使用带有 Tornado 的 REST GET 发回一个文件,但每次返回的文件的校验和都不同。 这背后的原因可能是什么?块返回的顺序是否错误?
我正在使用 curl 下载文件。
感谢您的建议! :-)
async def get(self, filename):
chunkSize = 1024 * 1024 * 1 # 1 Mib
with open(filename, 'rb') as f:
while True:
chunk = f.read(chunkSize)
if not chunk:
break
try:
self.write(chunk) # write the chunk to the response
await self.flush()# send the chunk to the client
except iostream.StreamClosedError:
break
finally:
del chunk
await gen.sleep(0.000000001)
self.finish()
编辑: 我尝试下载本地文件,发现文件开头添加了curl状态。
curl --user test -i -X GET http://localhost:8085/download/testfile.dat --output testfile.dat
使用不添加连接的 wget 效果更好。
wget --http-user=test --http-passwd=test http://localhost:8085/download/testfile.dat
【问题讨论】:
标签: rest file curl python-3.6 tornado