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.

25 lines
886 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)