loren880898
import oss2
import datetime
import string
import random
import requests


# 自定义随机名称
now = datetime.datetime.now()
random_name = now.strftime("%Y%m%d%H%M%S") + \'\'.join([random.choice(string.digits) for _ in range(4)])
# 自有域名
cname = \'https://****.com/\'
# 存放OSS路径
file_name = \'****/{}.jpg\'.format(random_name)
# AccessKeyID和AccessKeySecret
auth = oss2.Auth(\'****\', \'****\')
# 外网访问的Bucket域名和Bucket名称
bucket = oss2.Bucket(auth, \'*****\', \'*****\', is_cname=True)
# 图片链接
url = \'********\'
resp = requests.get(url).content
bucket.put_object(file_name, resp)
# 最终的图片链接
get_url = cname + file_name
print(get_url)

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2021-12-19
  • 2021-12-28
  • 2021-12-29
  • 2021-06-23
猜你喜欢
  • 2021-12-28
  • 2021-09-27
  • 2021-08-15
  • 2021-12-28
  • 2021-06-04
  • 2021-05-13
相关资源
相似解决方案