Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel AWS S3 Upload photo error (Region error?)

Error executing "ListObjects" on "https://s3.your-region.amazonaws.com/your-bucket?prefix=abc%2F1468895496.jpg%2F&max-keys=1&encoding-type=url"; AWS HTTP error: cURL error 6: Could not resolve host: s3.your-region.amazonaws.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\Filesystem\Filesystem;
use App\Product;
use Illuminate\Http\Request;
class ProductController extends Controller
{
...
public function store(Request $request)
    {
        $image = $request->file('file');
        $imageFileName = time() . '.' . $image->getClientOriginalExtension();
        $s3 = \Storage::disk('s3');
        $filePath = '/abc/' . $imageFileName;
        $s3->put($filePath, file_get_contents($image), 'public');
        return redirect()->action('ProductController@index');
    }
like image 751
Walker Base Avatar asked Jul 19 '16 02:07

Walker Base


1 Answers

I think you havent set the config in config/filesystems.php because the your-region, your-bucket etc is the default value.

Change at this section and make sure the key, secret, region and bucket are filled up.

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'visibility' => 'public',
    ],

    // s3 part is here
    's3' => [
        'driver' => 's3',
        'key' => 'your-key',
        'secret' => 'your-secret',
        'region' => 'ap-southeast-1', // this is the region setting
        'bucket' => 'your-bucket',
    ],

],
like image 77
xmhafiz Avatar answered Nov 20 '22 10:11

xmhafiz