【发布时间】:2021-04-23 07:55:23
【问题描述】:
我正在尝试从 SFTP 服务器获取字节文件并将其作为文件对象传递给 fastAPI 到服务器。
flo = BytesIO()
srv.getfo(file, flo)
kind = mimetypes.guess_type(file)
flo.seek(0)
return FileResponse(flo.read(), media_type=kind[0])
我收到此错误
AssertionError: 'aiofiles' must be installed to use FileResponse
所以我尝试了流式响应并得到一个空的下载文件。
return StreamingResponse(flo.read(), media_type=kind[0])
这是我的前端,只是使用了一个简单的 axios 获取和文件下载库
fileDownload(r.data, file)
【问题讨论】:
标签: fastapi