This commit is contained in:
Mrx
2026-05-29 21:13:46 +08:00
parent 4b1176b1e3
commit 5ee816d6c1
3 changed files with 61 additions and 26 deletions

View File

@@ -281,6 +281,15 @@ func (s *QiNiuStorageService) UploadFromReader(ctx context.Context, reader io.Re
return s.UploadFile(ctx, fileBytes, fileName)
}
// DownloadFileByKey 通过存储 key 下载文件(每次生成最新访问 URL避免私有空间签名过期
func (s *QiNiuStorageService) DownloadFileByKey(ctx context.Context, key string) ([]byte, error) {
if key == "" {
return nil, fmt.Errorf("文件 key 不能为空")
}
fileURL := s.GetFileURL(ctx, key)
return s.DownloadFile(ctx, fileURL)
}
// DownloadFile 从七牛云下载文件
func (s *QiNiuStorageService) DownloadFile(ctx context.Context, fileURL string) ([]byte, error) {
s.logger.Info("开始从七牛云下载文件", zap.String("file_url", fileURL))