python - 将文件上传到 s3 并取回公共 URL
问题描述
我正在尝试在 s3 Amazon 上使用 boto3 Python 上传 JSON 文件。文件上传成功,但我没有收到返回的公共 URL。
这是我的代码:
import boto3
from botocore.exceptions import NoCredentialsError
from credential import ACCESS_KEY , SECRET_KEY
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)
try:
s3.upload_file(local_file, bucket, s3_file)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
uploaded = upload_to_aws('temp_file.json', 'feed-crawler', '0output_test.json')
解决方案
推荐阅读
- javascript - 如何使用查询选择器选择属性内的属性?
- python - 如何在 Django 中通过 SQL 将连接和分组更改为 ORM
- html - 有一个悬停 CSS 状态是否也可以添加一个 CSS 点击状态?
- android - Flutter Background_fetch lib在终止应用程序后不运行
- java - 应用程序不断停止进程:com.example.test101,PID:7666 java.lang.RuntimeException:无法实例化活动
- .net-core - 使用 dotnet core 3.1 在 Windows 服务中检测终止请求
- python - 请求模块慢,因为 enconding
- python - 为什么字典理解显示不同的值
- tableau-api - 用 Tableau 中相同维度字段中的可用数据填充空白数据
- python - 通过 ssh 的 pynput 想要监控鼠标移动