小编Chi*_*lal的帖子

如何使用 boto3 在 s3 存储桶上上传 aws 文件成功的响应?

我知道如何使用 boto3 将文件上传到 s3 存储桶上。但我已经在我的函数中使用了它,我想检查图像是否成功上传到 s3 存储桶上,如果上传了,那么我想执行一个操作。

所以这是这样的例子,

import boto3

def upload_image_get_url(file_name, bucket, key_name):

   s3 = boto3.client("s3")

   result = s3.upload_file(file_name, bucket, key_name) # Here I got none so How I will check like file is upoaded or not?

   if result == 'success' or result == True:
       response = "https://{0}.s3.us-east-2.amCCazonaws.com/{1}".format(bucket, key_name)
   else:
       response = False

   return response


Run Code Online (Sandbox Code Playgroud)

所以我的要求很简单,就像如果我成功上传文件,那么我将返回 s3 url 作为响应。所以请帮助我,我们将不胜感激。

python amazon-s3 amazon-web-services boto3

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

amazon-s3 ×1

amazon-web-services ×1

boto3 ×1

python ×1