以zip格式获取目录中的所有文件



我可以在一个字典中获得我想要的所有文件,但当我想读取所有文件时,它只会返回带有API flask的字典的第一个文件,我不会返回所有文件,因为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调用一个对象(。

没有请求AmazonS3创建多个文件/文件夹的Zip文件的功能。

最新更新