You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import oss2
|
|
|
|
|
|
|
|
|
|
# pip install oss2
|
|
|
|
|
|
|
|
|
|
# 填写RAM用户的访问密钥(AccessKey ID和AccessKey Secret)。
|
|
|
|
|
accessKeyId = 'LTAI5tE4tgpGcKWhbZg6C4bh'
|
|
|
|
|
accessKeySecret = 'oizcTOZ8izbGUouboC00RcmGE8vBQ1'
|
|
|
|
|
|
|
|
|
|
# endpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
|
|
|
|
endpoint = 'http://oss-cn-beijing.aliyuncs.com'
|
|
|
|
|
# 填写Bucket名称。
|
|
|
|
|
bucketName = 'hzkc'
|
|
|
|
|
|
|
|
|
|
def uploadOss(key,localFile):
|
|
|
|
|
# 使用代码嵌入的RAM用户的访问密钥配置访问凭证。
|
|
|
|
|
auth = oss2.Auth(accessKeyId, accessKeySecret)
|
|
|
|
|
bucket = oss2.Bucket(auth, endpoint, bucketName)
|
|
|
|
|
|
|
|
|
|
# 上传文件到OSS。
|
|
|
|
|
# 设置上传时的元数据,指定Content-Type
|
|
|
|
|
headers = {'Content-Type': 'image/png', "Content-Disposition": 'inline'}
|
|
|
|
|
bucket.put_object_from_file(key, localFile, headers)
|