簡體   English   中英

使用Laravel 5.2上傳到S3

[英]Uploading to S3 with Laravel 5.2

Laravel 5.2的s3驅動程序有問題。 我得到的錯誤是這樣的:

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.

我正在使用Laravel文檔中所述的聯盟飛行系統V3。 當我遵循堆棧軌道並開始轉儲var時,“ Key”值始終為空,但我已將其全部設置在我的配置文件中。

這是我的堆棧跟蹤的最上面的幾行

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

如您所見,它是從我的配置中獲取存儲區,但不是從密鑰中獲取空值。

這是我的filesystem.php文件

        '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',
        ],

這是我的控制器,這很簡單,我認為看跌期權的內容不相關,但無論如何都添加了它

// 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));

您必須提供目標文件的路徑/名稱,以將其保存在S3存儲桶上作為put函數的第一個參數。 當前,您正在嘗試將文件保存到存儲桶的根目錄中,而不使用任何名稱。 嘗試這樣的事情:

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

文件的完整路徑是此上下文中的 ,也就是原始請求中所缺少的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM