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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记