Laravel 5.1 AWS S3 Flysytem: AWS HTTP error: cURL error 6: Couldn't resolve host name

4.5k views Asked by At

I'm on my local environment and are about to enable file uploading to AWS s3, using Laravel 5.1 Flysystem/Filesystem.

All setup has been done. I have created a test form, and I'm trying to upload a file. When I push the submit button, I get this absolutely, only too lovable error:

S3Exception in WrappedHttpHandler.php line 152:
Error executing "HeadObject" on "https://s3.Frankfurt.amazonaws.com/bucketName/resource-6";
AWS HTTP error: cURL error 6: Couldn't resolve host name

Sooo... where have I gone wrong? Here is my code:

FORM / VIEW

{!! Form::open([
        'route'         => 'resource-store',
        'class'         => 'uploadResource',
        'files'         => true
]) !!}

{!! Form::label('Resource title') !!}
{!! Form::text('title', null, ['placeholder'=>'Descriptive title']) !!}

{!! Form::label('Your Resource') !!}
{!! Form::file('resource', null) !!}

{!! Form::submit('Create Resource') !!}

{!! Form::close() !!}

CONTROLLER STORE METHOD

public function store(ResourceRequest $request, $id)
    {
        /* Store entry in DB */
        $resource = new Resource();
        $resource->title = $request->title;
        $resource->save();

        /* Process, Validate & Store Image */
        Storage::put(
            'resource-'.$resource->id,
            $resource
        );

        /* Success message */
        session()->flash('message', $request->title . ' er lavet/uploadet!');
        return redirect()->route('resource.index');
    }

DATABASE CONFIG

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'port'      => 33060,
        ],

CONFIG/FILESYSTEMS.PHP

return [

    'default' => 's3',
    'cloud' => 's3',

    'disks' => [

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

        's3' => [
            'driver' => 's3',
            'key'    => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

        'rackspace' => [
            'driver'    => 'rackspace',
            'username'  => 'your-username',
            'key'       => 'your-key',
            'container' => 'your-container',
            'endpoint'  => 'https://identity.api.rackspacecloud.com/v2.0/',
            'region'    => 'IAD',
        ],
    ],
];
1

There are 1 answers

1
MartinJH On BEST ANSWER

Typical. Realized what was wrong after reading this article by Paul Robinson.

I had set my s3 region to be Frankfurt. While my region sure enough is Frankfurt, I needed to refer to it as eu-central-1 as my s3 region in config/filesystems.php.

After that I could go on to fix my next error which was in the Storage::put() method.

WRONG

 Storage::put(
        'resource-'.$resource->id,
         $resource
 );

CORRECT

Storage::put(
        'resource-'.$resource->id,
        file_get_contents($request->file('resource'))
);

Hope this can help others. Have a terrific day/night/etc.