一、阿里云OSS API常用操作
1.上传
1.1 小文件上传(小于5GB)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import oss2 import os import sys oss_file_name=sys.argv[1] local_file_name=sys.argv[2] auth = oss2.Auth('LTAI5tKDLc6S2pkrcqyZHEh8', 'OJybPiQpyeS22tlKpmgaex1xxxxxx') bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'mqops-backup') bucket.put_object_from_file(filename=local_file_name,key=oss_file_name)
1.2 大文件上传(断点续传)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import oss2 import os import sys oss_file_name=sys.argv[1] local_file_name=sys.argv[2] auth = oss2.Auth('LTAI5tKDLc6S2pkrcqyZHEh8', 'OJybPiQpyeS2xxxxxx') bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'mqops-backup') oss2.resumable_upload(bucket, oss_file_name, local_file_name, multipart_threshold=100 * 1024) # 设置分片大小,单位为字节,取值范围为100 KB~5 GB。默认值为100 KB
标签:name,OSS,oss2,sys,阿里,file,import,操作,oss From: https://www.cnblogs.com/panwenbin-logs/p/17070883.html