赞
踩
建立aws账户,进入到S3界面
点击 "Create bucket"
一系列操作之后——这里给bucket命名为csfyp
python需要先:
- pip install loguru
- pip install boto3
这两个包含一些连接python和s3 连接的api
然后直接上代码
- import os
- import boto3
- from loguru import logger
-
-
- BUCKET_NAME = "csfyp" # 存储桶名称
-
- # aws_access_key_id和aws_secret_access_key
- CN_S3_AKI = ''
- CN_S3_SAK = ''
-
- CN_REGION_NAME = 'us-west-2' # 区域
-
- # s3 实例
- s3 = boto3.client('s3', region_name=CN_REGION_NAME,
- aws_access_key_id=CN_S3_AKI, aws_secret_access_key=CN_S3_SAK
- )
-
-
- def upload_files(path_local, path_s3):
- """
- 上传(重复上传会覆盖同名文件)
- :param path_local: 本地路径
- :param path_s3: s3路径
- """
- logger.info(f'Start upload files.')
-
- if not upload_single_file(path_local, path_s3):
- logger.error(f'Upload files failed.')
-
- logger.info(f'Upload files successful.')
-
-
- def upload_single_file(src_lo
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。