对于AWS S3和Python / Flask / Boto3,如何在浏览器中查看文件而不是直接下载?
我有这样的事情:
@app.route('/dl')
def dl():
bucketName = "uw-note-share"
key = "question4.png"
s3.Bucket(bucketName).download_file(key, 'my_local_image.jpg')
return "truu"
但是这个将文件下载到我的磁盘位置,如果我只想在浏览器中查看文件,如图像链接在线?
谢谢!
答案 0 :(得分:0)
url = s3.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': 'bucket-name',
'Key': 'key-name'
}
)
response = requests.get(url)
来源:http://boto3.readthedocs.io/en/latest/guide/s3.html#generating-presigned-urls