json - 以 zip 格式获取目录中的所有文件
问题描述
我能够在一个字典中获取我想要的所有文件,但是当我想读取所有文件时,它只返回带有 API 烧瓶的字典的第一个文件,我不会返回所有文件,如 zip会好的。
def download():
"""
API Endpoint responsible for download student
:return:
"""
# If a valid payload wasn't sent just return a 404
if not request.json:
return jsonify({"results": "404", "description": "invalid payload sent"}), 404
# Load the payload
payload = request.json
# TODO Flesh this out with proper security or else anyone can do a POST and auth in
# TODO Most likely need to create a common module for this
status_code = 200
my_response = {
"results": {},
"description": "",
}
if "studentid" in payload and "assignmentid" in payload:
student_id = payload["studentid"]
assignment_id = payload["assignmentid"]
folder = download_for_single_student(student_id,assignment_id)
return Response(
folder['Body'].read(),
mimetype='application/pdf',
headers={"Content-Disposition": "attachment:report.pdf"}
)
else:
status_code = 400
my_response[
"description"
] = "Please ensure both studentid and assignmentid are in the request payload"
print("Studentid and/or Assignmentid not found in request")
return jsonify(my_response), status_code
解决方案
您一次只能从 Amazon S3 下载一个对象(即每个 API 调用一个对象)。
没有请求 Amazon S3 创建包含多个文件/文件夹的 Zip 文件的功能。
推荐阅读
- python - 我应该如何存储它,我该怎么做?不和谐.py
- swift - Swift shell 命令返回空结果
- python - TensorFlow - ValueError:检查点版本应为 V2
- c - 寻找素因数分解的程序
- javascript - 隐藏的 Tailwind 移动设备无法正常工作
- powershell - 如何使用 AWS PS Cmdlet 按标签搜索:Get-EC2Subnet
- visual-studio-code - 如何找到每个版本的 Visual Studio Code 附带的节点版本
- docker - Jenkins Pipeline - 使用 SSH 凭据连接到 Docker 主机
- sql-server - SQL Server 2019 的 TempDB 缓存问题
- angular9 - 默认情况下,Angular 8 Material mat-error 在加载时显示