七牛云私有链接访问失败:download token auth failed (已解决) /对象存储/私有图床
·
前情提要
作者后端springboot3,上传图片(私有)后试图用一小时有效期的带token链接访问,然后发现不行。
一开始的生成url代码如下:
return auth.privateDownloadUrl(domain + "/" + fileKey, 3600)
查文档
原文 :· download token auth failed 表示 token 错误,说明生成 token 的算法有问题,建议直接使用七牛的服务端 SDK 生成 token。
也就是说。
七牛云自己的privateDownloadUrl生成算法有问题……
解决方案
换成七牛云的另一个生成算法……
import com.qiniu.storage.DownloadUrl;
//中间那个false是代表 ‘是否使用https’
DownloadUrl url = new DownloadUrl(domain, false, fileKey);
long expireInSeconds = 3600;//依旧1小时~
long deadline = System.currentTimeMillis()/1000 + expireInSeconds;
try {
return url.buildURL(auth, deadline);
}catch (QiniuException e)
{
System.out.println("生成访问URL失败:" + e.getMessage());
return null;
}
点个赞和收藏吧亲~★,°:.☆( ̄▽ ̄)/$:.°★ 。
更多推荐


所有评论(0)