2016-06-07 154 views
0

我試圖通過laravel應用程序將圖像上傳到S3。Laravel上傳到s3的圖像是0kb?

public function createFeature($id, Request $request) 
{ 
    $refererURL = explode('/', URL::previous()); 
    $refererID = $refererURL[6]; 

    if ($refererID !== $id) { 
     return redirect()->back(); 
    } 

    $file = $request->file('feature_image'); 

    if ($file === null) { 
     return redirect()->back(); 
    } 

    if (!$this->isAllowedFile($file)) { 
     return redirect()->back(); 
    } 

    $name = str_random(255) . '-feature-' . '.' . $file->getClientOriginalExtension(); 

    Storage::disk('s3')->put($this->buildFilePath($name, $id), file_get_contents($file->getRealPath())); 

    // Store in a database 
    Media::create([ 
     'deal_id' => $id, 
     'key' => 'feature', 
     'value' => $name, 
     'original' => $file->getClientOriginalName() 
    ]); 

    return redirect()->back(); 

} 

問題是,它有時會起作用,有時它不起作用。我的意思是,AWS S3控制檯中的圖像對象爲0 kb

當我打開圖像時,它只是空白。

我採用這種封裝形式: 「聯盟/ flysystem-AWS-S3-V3」: 「^ 1.0」,

我做了什麼解決問題,以獲得更多的信息是使日誌記錄。我只是啓用日誌記錄,所以我還沒有得到任何東西。

謝謝您花時間幫忙。

回答

0

首先你需要在composer.json和更新作曲家添加此2包

"aws/aws-sdk-php-laravel": "~3.0", 
"league/flysystem-aws-s3-v3": "^1.0", 

我也使用相同的封裝,它在我的

$extension = $file->getClientOriginalExtension(); 
$imageName = rand(11111, 99999) . '.' . $extension; // rename image 
$key = Auth::user()->id."/". $imageName; 
Storage::disk('s3')->put($key, file_get_contents($file)); 
做工精細的