大文件分段上传 获取需要追加上传的对象信息 response s3client.headobject(Bucket"bucketblocks", Key"mac.txt") 获取当前对象长度 appendPos response['ContentLength'] s3client.putobject(Bucket'输入要传入的桶名', Metadatadict(m1'm1'), Bodydata, Key'输入存入后对象的键值', ContentMD5str(md5, 'utf8'), AppendTrue, 开启追加上传 AppendPositionappendPos) 指定追加上传开始的位置 整体代码 python from boto3.session import Session import hashlib import base64 accesskey "此处输入你的Access Key" 这里输入你的Access Key secretkey "此处输入你的Secret Key" 这里输入你的Secret Key url "此处输入你的endpoint" 这里输入你的endpoint 上传文件桶的桶名 bname '输入要传入的桶名' 文件在桶内存储的key值 key '输入存入后对象的键值' 追加上传开始的位置,默认为0 appendPos 0 try: 读取文件并记录文件md5值 with open('输入要上传文件的路径', 'rb') as file: data file.read() md5 hashlib.md5(data).digest() md5 base64.b64encode(md5) 获取对象存储服务的操作客户端 session Session(accesskey, secretkey) s3client session.client("s3", endpointurlurl) 获取桶内所有对象信息 response s3client.listobjects(Bucketbname) 遍历所有对象键值 for obj in response['Contents']: 桶中存在与待上传对象同key的对象,需要判断该对象能否进行追加上传 if obj['Key'] key: res s3client.headobject(Bucketbname, Keykey) if res['ResponseMetadata']['HTTPHeaders']['xrgwobjecttype'] ! 'Appendable': print('该对象不是Appendable类型,无法进行追加上传.') raise Exception