【问题标题】:Laravel 5.6 - Upload stored file to S3Laravel 5.6 - 将存储的文件上传到 S3
【发布时间】:2018-07-02 22:52:02
【问题描述】:

我有一个 Laravel 5.6 项目,它使用 Storage 门面存储图像。

我正在尝试拍摄我存储的图像并将其移动到 S3 存储,就像这样..

$contents = Storage::disk('local')->url($image->filename);
$storagePath = Storage::disk('s3')->put("uploads", $contents, 'public');

这会将文件上传到名为“uploads”的 S3 存储桶,其中包含文件的路径,如下所示...

/storage/myimage.jpg

如何上传实际文件而不是保存路径?

【问题讨论】:

标签: php laravel laravel-5


【解决方案1】:

你可以这样做:

$contents = Storage::get('file.jpg');

File System Laravel

【讨论】:

  • 我一直在尝试这样做 $contents = Storage::get($image->filename);但我不断收到文件未找到错误
  • 所以你存储在数据库中的路径错误或者文件夹和数据库中的文件名不同
  • 文件名是正确的,但我对路径设置的位置感到困惑。 Storage::get 不会自动添加存储路径吗?
  • Storage::get($file) 它需要完整路径以及文件名
  • @fightstarr20 你能在 storage/app/ 中看到你的文件吗,如果是,那么尝试在 Storage::get($filenmae) 中硬编码文件名,然后尝试获取它的内容。
【解决方案2】:

添加use Illuminate\Support\Facades\Storage;

你可以这样做:

$contents = Storage::get('file.jpg');

File System Laravel

【讨论】:

    猜你喜欢
    • 2021-02-07
    • 2020-10-10
    • 2023-02-12
    • 2018-02-16
    • 2018-04-25
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2018-03-25
    相关资源
    最近更新 更多