fix: Qiniu 下载改用 privateDownloadUrl 手动拼接

This commit is contained in:
mediabot-pt
2026-06-30 18:21:25 +08:00
parent abb6047277
commit 6c7549ca8e

View File

@@ -3,7 +3,6 @@ package com.par.core.storage;
import com.qiniu.common.QiniuException;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.DownloadUrl;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
@@ -93,11 +92,10 @@ public class QiniuStorageService implements StorageService {
log.warn("Qiniu stat 失败 {}: {}", path, e.response != null ? e.response.error : e.getMessage());
}
// 用 DownloadUrl 生成带签名的下载链接
long deadline = System.currentTimeMillis() / 1000 + 3600;
// 手动拼接 URL + privateDownloadUrl 签名
String baseUrl = "http://" + downloadDomain + "/" + path;
String signedUrl = auth.privateDownloadUrl(baseUrl, 3600);
try {
DownloadUrl url = new DownloadUrl(downloadDomain, useHttps, path);
String signedUrl = url.buildURL(auth, deadline);
var req = HttpRequest.newBuilder().uri(URI.create(signedUrl))
.timeout(Duration.ofSeconds(10)).GET().build();
var resp = httpClient.send(req, HttpResponse.BodyHandlers.ofString());