ShankarsbavanS's avatar

Laravel file upload not working in S3

I'm trying to upload files to AWS S3 bucket. Here is my form and controller

<form action="{{ url('/') }}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
   <input type="file" name="image" id="image">
   <button type="submit">Save</button>
</form>
$file = $request->file('image');
$name = 'imgname.jpg';
$filePath = 'images/' . $name;
Storage::disk('s3')->put($filePath, file_get_contents($file));

Also I added AWS Credentials in .env file.

Laravel version 6.0

I got following error when I upload file.

GuzzleHttp\Exception\ConnectException cURL error 28: (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@shankarsbavans

It seems that, you have some credential issues in AWS. Make sure you have the right access.

Here is the sample of credential of S3.

's3' => [
            'driver' => 's3',
            'key' => 'KxxxxxxxN',
            'secret' => 'fSFrxxxxxxxxxx',
            'region' => 'us-east-1',
            'bucket' => 'bucket-name',
            'url' => 'http://s3.us-east-1.amazonaws.com/bucket-name',
        ],
6 likes

Please or to participate in this conversation.