【问题标题】:Amazon aws - s3 bucket not uploading image - It creates only the keyAmazon aws - s3 存储桶不上传图片 - 它只创建密钥
【发布时间】:2016-01-21 18:31:26
【问题描述】:

我正在使用 Laravel 5.0 并使用 "aws/aws-sdk-php-laravel": "~2.0"

这是我上传图片的脚本

$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
    'Bucket'     => 'greenhoppingbucket',
    'Key'        => 'sups',
    'Body'        => Input::file('file'),

));

执行后只有密钥被上传到 s3 桶中

即,sups 是创建存储桶而不是图像。

我做错了什么,我该如何解决这个问题

【问题讨论】:

    标签: php laravel amazon-web-services amazon-s3 laravel-5


    【解决方案1】:

    试试这个:

    $s3 = App::make('aws')->get('s3');
    $s3->putObject(array(
        'Bucket'     => 'greenhoppingbucket',
        'Key'        => 'sups',
        'Body'        => File::get((string)Input::file('file')),
    
    ));
    

    别忘了加use File;

    当您执行 'Body' => Input::file('file') 时,您基本上将临时路径放入正文而不是文件的内容。

    File::get 只是获取文件的内容

    【讨论】:

    • 谢谢,让我尽快转告你
    猜你喜欢
    • 1970-01-01
    • 2017-12-23
    • 2017-10-14
    • 2017-03-13
    • 2017-06-26
    • 2017-04-24
    • 2022-01-12
    • 1970-01-01
    • 2018-04-12
    相关资源
    最近更新 更多