zgldh / qiniu-laravel-storage

Qiniu 云储存 Laravel 5 Storage版
MIT License
521 stars 79 forks source link

setDownload() can not rename the file #42

Closed Lostvincent closed 7 years ago

Lostvincent commented 7 years ago

When I use

$disk->privateDownloadUrl('old', ['domain' => 'xxx', 'expires' => xxx])->setDownload('new')->getUrl();

to rename the file I download, the name is still 'old' without any change.

BTW, I find the url is same whether use setDownload() or not (except token part), does it not work on private bucket?

zgldh commented 7 years ago

不使用 getUrl() 而是将其强制转换为 string

$url = $disk->privateDownloadUrl('old', ['domain' => 'xxx', 'expires' => xxx])->setDownload('new').'';

试试看。

Lostvincent commented 7 years ago

我尝试过直接转成 string,或者 jsonSerialize() 处理,返回 url 多了 /download 部分,然后就提示资源不存在了,不加的话没事

zgldh commented 7 years ago

将得到的完整url贴出来看看,比对下七牛官方文档看是不是哪儿参数不对

Lostvincent commented 7 years ago

无 setDownload: https://example.com/origin.rmskin?e={xxx}&token={xxx}= 有 setDownload: https://example.com/origin.rmskin?e={xxx}&token={xxx}=&download/test.rmskin

测试结果加不加没什么用,如果能下载,还是 origin.rmskin,其中 xxx 部分完全相同(我在同一次请求中分别生成的两个,区别只有 setDownload('test.rmskin') 的调用与否)

实际代码

$url = $disk->privateDownloadUrl($skin->path.$release->version.$release->ext, ['domain' => 'https', 'expires' => 600]).'';
$reurl = $disk->privateDownloadUrl($skin->path.$release->version.$release->ext, ['domain' => 'https', 'expires' => 600])->setDownload('test.rmskin').'';

dd($url, $reurl);

补:&download/ 这个用法我暂时并未在文档中找到,可否提供点关键词?

zgldh commented 7 years ago

我测试一下。。可能我哪儿写错了

zgldh commented 7 years ago

经过检查, setDownload 只对公有资源有效。 私有资源暂时无效。 建议这样试试:

$reurl = $disk->privateDownloadUrl($skin->path.$release->version.$release->ext.'?attname=test.rmskin', ['domain' => 'https', 'expires' => 600]).'';
Lostvincent commented 7 years ago

经过测试 ?attname=test.rmskin 有效,感谢解答,可随时关闭 issue

zgldh commented 7 years ago

原因是 attname 参数也要参与到私有资源签名算法中,必须提前给出。 而本库设计的 setDownload 的执行时机已经晚于签名生成了。