【问题标题】:how to upload local image to s3 and use its link to view the image如何将本地图像上传到 s3 并使用其链接查看图像
【发布时间】:2022-07-21 23:48:51
【问题描述】:

我想将本地图像上传到 s3 并使用链接查看这些图像,而不是下载它们当前当我在浏览器中打开链接时,我正在上传的图像正在下载。我还在 AWS 元数据中将内容类型添加到 image/png 中,但目前正在下载它我在 python 中使用这个函数来上传图像

uploaded = upload_to_aws('file.png', 's3','file.png')

功能

def upload_to_aws(local_file, bucket, s3_file):
    s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)
    s3.upload_file(local_file, bucket, s3_file)
    print("Upload Successful")
    return True

【问题讨论】:

  • funcuplodad是如何定义的?
  • 抱歉我忘记了
  • 上传文件时,为什么不动态生成一个html文件并上传所有图片链接?
  • 能发个demo吗

标签: python boto3


【解决方案1】:

根据 S3.upload_file 上的 boto3 文档,看起来您在调用 upload_file() 方法时必须将 ExtraArgs 作为 dict 参数传递。

另请注意,允许的上传参数记录在 here

例如:

s3.upload_file(local_file, bucket, s3_file, 
               ExtraArgs=dict(ContentType='image/png))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 2020-12-04
    相关资源
    最近更新 更多