要使用Flask从S3下载文件,我正在使用以下代码:
@app.route('/downloads3', methods=['GET','POST'])
def download_s3():
if not google.authorized:
return redirect(url_for("google.login"))
resp = google.get("/oauth2/v2/userinfo")
tekst = resp.text
user_data = json.loads(tekst)
user_id = user_data['id']
s3 = boto3.resource('s3')
fileid = request.form.get('file_id')
try:
s3.Bucket(user_id).download_file(str(fileid),current_app.root_path(str(fileid)))
return 'gedownload'
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")
else:
raise
return redirect('/s3')
文件已下载到服务器,但我希望文件下载到客户端。