简体   繁体   English

Laravel 4 Response :: download()来自外部网址源代码

[英]Laravel 4 Response::download() from external url source

I can't seem to find out whether it is possible to create a download link via Response::download() method with an external URL file source instead of local file path. 我似乎无法找出是否可以通过Response::download()方法创建一个下载链接,使用外部 URL文件源而不是本地文件路径。 For example: 例如:

Response::download('https://s3.amazonaws.com/bucket/file.zip','Download.zip');

I'm hosting my static and upload file on Amazon S3 and would like to create a download link when the requested users have access to it. 我在Amazon S3上托管我的静态和上传文件,并希望在请求的用户可以访问它时创建下载链接。 All I get from the testing above is a FileNotFoundException error popping up stating that file does not exist. 我从上面的测试得到的是一个FileNotFoundException错误弹出声明该文件不存在。

As @James Binford said in the comments, it is not possible to use Response::download() for files on an external source. 正如@James Binford在评论中所说,不可能将Response::download()用于外部源上的文件。 It may not be perfect, but you can always redirect to the URL 它可能不完美,但您始终可以重定向到URL

Redirect::away('https://s3.amazonaws.com/bucket/file.zip');

Depending on the file type it will open as "normal" download (eg zip files) or, if the browser supports it, the contents of the file will be displayed (eg images or text files) 根据文件类型,它将打开为“正常”下载(例如zip文件),或者,如果浏览器支持,则将显示文件的内容(例如图像或文本文件)

Alternatively you can download the file from the server to the application server (eg using curl ) and then use Response::download() 或者,您可以将文件从服务器下载到应用程序服务器(例如使用curl ),然后使用Response::download()

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

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