我想创建一个可以使用POST方法接受视频文件的API,并且POST方法在对视频进行处理后将返回zip文件名。使用该文件名,API应该使用GET方法返回zip文件。 我无法使用Flask-Restplus的Swagger UI的GET请求下载文件。
我尝试了一些互联网解决方案,但无法解决。我尝试使用@api.representation('application/zip')
来更改响应内容类型,但随后也无法下载。
upload_parser = api.parser()
upload_parser.add_argument('file', location='files', type=FileStorage, required=True)
download_parser = api.parser()
download_parser.add_argument('filename', type=str, required=True)
....
@api.route('/upload')
class Upload(Resource):
@api.expect(upload_parser)
def post(self):
args = upload_parser.parse_args()
uploaded_file = args['file'] # This is FileStorage instance
uploaded_file.save('F:/IT Sem-7/Internship/demo/uploaded_file.mp4')
zipObj = ZipFile('uploaded_file.zip', 'w')
zipObj.write('uploaded_file.mp4')
zipObj.close()
return {'Output': 'file uploaded successfully', 'filename': 'uploaded_file.zip'}, 201
@api.route('/download')
@api.representation('application/zip')
class Download(Resource):
@api.expect(download_parser)
def get(self):
args = upload_parser.parse_args()
return send_file('F:/IT Sem-7/Internship/demo/'+args['filename'],
mimetype='application/zip', attachment_filename=args['filename'],
as_attachment=True)
#return send_from_directory('F:/IT Sem-7/Internship/demo/',
args['filename'])
Swagger用户界面Swagger UI Error Image的错误