Laravel 5 Flysystem-从远程磁盘下载文件 [英] Laravel 5 Flysystem - download file from remote disk

查看:459
本文介绍了Laravel 5 Flysystem-从远程磁盘下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flysystem在Rackspace上存储网站的文件.上传没有问题,无法弄清楚如何开始下载文件-这是我尝试过的

I am storing files for a site on Rackspace using Flysystem. Uploading is no problem, having trouble figuring out how to start a download for a file - this is what I have tried

Storage::disk('rackspace');
return response()->download('file-library/' . $file->filename);

结果是找不到文件.添加Storage::disk()是否足以使Laravel在此位置(而不是在本地)显示?最好的方法是什么?

The result is that the file could not be found. Is adding Storage::disk() sufficient for making Laravel look in this location rather than locally? What is the best way to accomplish this?

推荐答案

在此处从Flysystem上找到.

Frank here from Flysystem.

执行此操作的首选方法是将readStream输出与Response :: stream结合使用.

The preferred way to do this would be to use the readStream output in combination with Response::stream.

<?php

$fs = Storage::disk('diskname')->getDriver();
$stream = $fs->readStream($file);

return Response::stream(function() use($stream) {
    fpassthru($stream);
}, 200, [
    "Content-Type" => $fs->getMimetype($file),
    "Content-Length" => $fs->getSize($file),
    "Content-disposition" => "attachment; filename=\"" . basename($file) . "\"",
]);

$fsLeague\Flysystem\Filesystem实例.我相信Laravel提供的文件系统类中有一种检索此实例的方法.

The $fs is the League\Flysystem\Filesystem instance. I believe there is a method to retrieve this instance in the filesystem class Laravel provides.

这篇关于Laravel 5 Flysystem-从远程磁盘下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆