python上传大文件s3_Python上传文件到S3,python,s3

import os

import boto3

AWS_ACCESS_KEY_ID = '*****************************'

AWS_SECRET_ACCESS_KEY = '*****************************'

AWS_BUCKET_NAME = '******'

#[AWS_ACCESS_KEY_ID 和AWS_SECRET_ACCESS_KEY 获取地址](https://console.aws.amazon.com/iam/home?region=ap-east-1#/security_credentials)

session = boto3.Session(

aws_access_key_id=AWS_ACCESS_KEY_ID,

aws_secret_access_key=AWS_SECRET_ACCESS_KEY,

region_name='ap-east-1' #这个必须加,不然会报错,此处根据自己的 s3 地区位置改变

)

def upload_file_to_s3(complete_file_path):

"""

Uploads a file to AWS S3. Usage:

>>> upload_file_to_s3('/tmp/business_plan.pdf')

"""

if complete_file_path is None:

raise ValueError("Please enter a valid and complete file path")

session = boto3.Session(

aws_access_key_id=AWS_ACCESS_KEY_ID,

aws_secret_access_key=AWS_SECRET_ACCESS_KEY,

region_name='ap-east-1'

)

s3 = session.resource('s3')

data = open(os.path.normpath(complete_file_path), 'rb')

file_basename = os.path.basename(complete_file_path)

s3.Bucket(AWS_BUCKET_NAME).put_object(Key=file_basename, Body=data)

upload_file_to_s3(r'D:\google\report.csv')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值