需要上传图片URL进行识别
进入https://help.aliyun.com/document_detail/155645.html?spm=api-workbench…0.0.33171e0fRQiZ2X
利用oss存储图片并转换为URL形式
上传我们的文件
复制图片URL链接
采用如下代码获取URL
from viapi.fileutils import FileUtils file_utils = FileUtils("LTAI5t8DuJ5bKttW4QkM3Rh9","a6EHULocaiqmbvXjrjBqOL16zhjpq9") oss_url = file_utils.get_oss_url('https://otstest.oss-cn-beijing.aliyuncs.com/train/0_Anger/1.jpg?Expires=1636356165&OSSAccessKeyId=TMP.3KjPYnBNhd32RkJLqnMooNkMVqzvbbmdNsPPrsDnvCz8dmXaK3HARk3nukYE5SUSXCSK1wxhhez8WvehUy5YGPutHQNbL9&Signature=5f5m4gbW41JEjKGn4f4YyIgDxkM%3D&versionId=CAEQFRiBgICyuI6T5xciIDQyM2Q3MjIxZDJhYzRlNjg4NTI0ZTc0YTk3NDk1ZDIw&response-content-type=application%2Foctet-stream',"jpg",False) print(oss_url)
http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAI5t8DuJ5bKttW4QkM3Rh9/588f267d-ecf4-46db-9fa4-5463e2147d48.jpg
调用结果
接下来我们利用代码获取URL
# -*- coding: utf-8 -*- from itertools import islice import oss2 # 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 auth = oss2.Auth('LTAI5t8DuJ5bKttW4QkM3Rh9', 'a6EHULocaiqmbvXjrjBqOL16zhjpq9') # Endpoint以杭州为例,其它Region请按实际情况填写。 bucket = oss2.Bucket(auth, 'oss-cn-beijing.aliyuncs.com/testface', 'otstest') # 列举存储空间下所有文件。 from viapi.fileutils import FileUtils file_utils = FileUtils("LTAI5t8DuJ5bKttW4QkM3Rh9", "a6EHULocaiqmbvXjrjBqOL16zhjpq9") for obj in oss2.ObjectIterator(bucket): # print(obj) jpg_url = bucket.sign_url('GET', obj.key, 60) if jpg_url.split('/')[3].split('%')[0] == 'test': #获取图片类型 classtype = jpg_url.split('/')[3].split('%')[1][2:] #url转换 oss_url = file_utils.get_oss_url(jpg_url, "jpg", False) print(oss_url)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)