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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊