aws s3 python3 boto3 对接易华录的蓝光测试

 通过ssl https ak sk 对接 获取桶名称和上传文件1.txt

第一步 使用boto3.resource 创建连接

第二步列出桶名称s3.buckets.all()

第三步上传文件s3.meta.client.upload_file

import urllib3
import boto3
import datetime
urllib3.disable_warnings()

s3 = boto3.resource(
  service_name='s3',
  aws_access_key_id="xxxxxxxxxxxxxxxx",
  aws_secret_access_key="oooooooooooooooooooooF",
  endpoint_url='https://172.20.2.2:9000',
  verify=False
)

# str_bucket_name = "bucket_test"
# s3.create_bucket(Bucket=str_bucket_name)


for bucket in s3.buckets.all(): # 获取所有bucket
  # 将实际转为本地时间
  print({"name": bucket.name, "create_date": datetime.datetime.strftime(bucket.creation_date + datetime.timedelta(hours=8), "%Y-%m-%d %H:%M:%S")})

# 删除指定的bucket
# for bucket in s3.buckets.all():
  # if bucket.name == str_bucket_name:
    # bucket.objects.all().delete()  # 等价于下面两行
    # # for obj in bucket.objects.all():
    # #   obj.delete()
    # bucket.delete()

# 存储文件流或字符串中的数据
# s3.Object('mybucket', 'hello.txt').put(Body=open('/tmp/hello.txt', 'rb'))

LOCAL_FILE = '1.txt'
BUCKET = 'mybucket'

# Upload file to Y/M/D/random-id/filename
#s3_client = boto3.client('s3', region_name='ap-southeast-2')
path = datetime.datetime.now().strftime("%Y/%m/%d/")  + '/'
print(path)
response = s3.meta.client.upload_file(LOCAL_FILE, BUCKET, path + LOCAL_FILE)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三块钱0794

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值