dream02008 2016-01-03 23:13
浏览 140
已采纳

使用Laravel 5.2上传到S3

Having an issue with the s3 driver for Laravel 5.2. The error i'm getting is this:

Found 1 error while validating the input provided for the HeadObject operation:
[Key] must be at least 1 characters long. Value provided is 0 characters long.

I'm using the league flysystem V3 as stated in Laravel docs. When I follow the stack track and start dumping out the vars the 'Key' value is always empty but i've set it all up in my config file.

Here are the top lines from my stack trace

in Validator.php line 38
at Validator->validate('HeadObject', object(StructureShape), array('Bucket' => 'monstervsl', 'Key' => '', '@http' => array())) in Middleware.php line 77
at Middleware::Aws\{closure}(object(Command), null) in S3Client.php line 710
at S3Client::Aws\S3\{closure}(object(Command), null) in S3Client.php line 729
at S3Client::Aws\S3\{closure}(object(Command), null) in Middleware.php line 53
at Middleware::Aws\{closure}(object(Command), null) in SSECMiddleware.php line 59
at SSECMiddleware->__invoke(object(Command)) in AwsClient.php line 208

As you can see it's getting the bucket from my config but not the key it's empty.

Here is my filesystem.php file

        's3' => [
            'driver' => 's3',
//            'key'    => env('S3_KEY'),
//            'secret' => env('S3_SECRET'),
            'key' => '8tfnxo8abgn7voaex8rgv', // <- Not my real key 
            'secret' => 'aw7btx49wXNF7AGWV', //  <- not my real secret
            'region' => 'eu-west-1',
            'bucket' => 'monstervsl',
        ],

Here is my controller, it's fairly straight forward, I don't think the put contents stuff is relevant but added it anyway

// Write the contents to a new file on disk
$view = view('iframe')->with('json', $video->toJson());
$contents = $view->render();
$token = '12345';
$filePath = public_path() .'/iframes/' . $token . '.html';
file_put_contents($filePath, $contents);

Storage::disk('s3')->put('/', file_get_contents($filePath));
  • 写回答

1条回答 默认 最新

  • dongmeijian1716 2016-01-04 07:03
    关注

    You have to give the destination file path/name where you want to save this file on S3 bucket as the first argument of put function. Currently you are trying to save the file at the root of bucket without any name. Try something like this:

    Storage::disk('s3')->put('filename.html', file_get_contents($filePath));
    

    This full path of the file is the Key in this context & that is what's missing in your original request.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题