简体   繁体   English

使用Laravel从Amazon S3直接下载到客户端

[英]direct download from amazon s3 to client using laravel

I'm trying to make my client side download a big file directly from amazon s3, without downloadin it through the server 我正在尝试让客户端直接从Amazon s3下载一个大文件,而不通过服务器下载它

using this function: 使用此功能:

        $downloadUrl = $s3->getObjectUrl('dev-checkmate', '1.zip', '+5 minutes', array(
            'ResponseContentDisposition' => 'attachment; filename="test.zip"','Content-Type' => 'application/zip',
    ));
    return $downloadUrl;

gives me back a valid url that i can paste to the browser and the download will start, how can i make my web page to start that download without redirecting to the user to the url? 给我一个有效的网址,我可以将其粘贴到浏览器中,下载将开始,如何制作我的网页以开始下载而无需将用户重定向到该网址? (i dont want him to get a blank page, i want him to stay in my web page) (我不希望他得到空白页,我希望他留在我的网页中)

or maybe there is a differnet approach to make the user start the download from s3 directly? 还是有一种不同的方法可以使用户直接从s3开始下载? the reason i dont want to use my server to do that is the files are pretty big, and i have slow bandwidth on my server. 我不想使用我的服务器来执行此操作的原因是文件很大,并且我的服务器带宽较慢。

I suggest you use javascript to open the download URL in a new window/tab. 建议您使用javascript在新窗口/标签中打开下载URL。 Usually if the browser detects the download the white page closes automatically. 通常,如果浏览器检测到下载,则白页会自动关闭。

Here's an example that fetches the download URL and then makes the redirect: 这是一个获取下载URL然后进行重定向的示例:

$.ajax({
    url: '/download/test.zip', // change this to your real URL
    type: 'GET'
}).done(function(data){
    window.open(data);
});

Alternatively you could insert the download URLs when rendering the view so you don't need to make that ajax call. 另外,您可以在呈现视图时插入下载URL,因此无需进行该Ajax调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM