【问题标题】:storing files to aws s3 using laravel使用 laravel 将文件存储到 aws s3
【发布时间】:2017-11-18 13:50:58
【问题描述】:

请给我一个在 laravel 5.5 中将文件存储到 AWS S3 的示例。 我已经使用 AWS 凭证配置了文件系统文件。

我看到了函数

Storage::put('file.jpg', $contents);

但不知道第二个参数是什么

filesystem.php文件内容如下

return [


    'default' => env('FILESYSTEM_DRIVER', 'local'),



    'cloud' => env('FILESYSTEM_CLOUD', 's3'),


    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => '*********',
            'secret' => '******',
            'region' => 'my region',
            'bucket' => 'bucketname',
        ],

    ],

];

提前致谢

【问题讨论】:

  • 向我们展示您的filesystems.php的内容
  • 第二个参数是文件的实际原始内容(字符串)或 PHP 资源(例如文件流句柄)。 documentation 确实这么说。
  • 更新了有问题的文件系统内容,你能举个例子吗

标签: laravel laravel-5 amazon-s3 laravel-5.5 laravel-filesystem


【解决方案1】:

Laravel documentation中有很好的例子:

Storage::disk('s3')->put('avatars/1', $fileContents);

第二个参数是文件内容,所以在现实生活中它可能看起来像这样:

Storage::disk('s3')->put('file.jpg', file_get_contents('your_local_file.jpg');

【讨论】:

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