Laravel's Filesystem with s3 using the wrong url
Asked Answered
T

1

9

I am using Laravel's Filesystem to store items on s3 and I am getting the wrong URL.

Storage::disk('s3')->put('file.txt', 'Contents');

Gives me the error

CurlException in CurlMulti.php line 359:
[curl] 6: Could not resolve host: mybucket.s3.website-us-east-1.amazonaws.com [url] https://mybucket.s3.website-us-east-1.amazonaws.com/file.txt

This URL

mybucket.s3.website-us-east-1.amazonaws.com

should be

mybucket.s3-website-us-east-1.amazonaws.com

config/filesystem.php

's3' => [
    'driver' => 's3',
    'key'    => env('S3_KEY'),
    'secret' => env('S3_SECRET'),
    'region' => env('S3_REGION'),
    'bucket' => env('S3_BUCKET'),
],

.env

S3_KEY=MYKEY
S3_SECRET=mySecr3tmySecr3tmySecr3tmySecr3t
S3_REGION=website-us-east-1
S3_BUCKET=mybucket
Truda answered 3/4, 2015 at 17:18 Comment(5)
Perhaps S3_REGION=s3-website-us-east-1...?Gehman
Yeah, I tried that it gave me mybucket.s3.s3-website-us-east-1.amazonaws.comTruda
As was added here, the solution to remove region worked for me: laravel.io/forum/…Escape
@mklinker, thanks for the update. I actually found another solution to that allowed me to keep the region reference. I answered my own question in case it helps anybody else.Truda
I just had this issue today, on with two separate servers and projects. Resetting NGINX and PHP FPM fixed it. I am not clear why doing that sorted it tho...Infanticide
T
23

I eventually found two answers for this.

One solution was to remove the region reference entirely

's3' => [
    'driver' => 's3',
    'key'    => env('S3_KEY'),
    'secret' => env('S3_SECRET'),
    'bucket' => env('S3_BUCKET'),
],

The other solution which is what I eventually went with was this:

's3' => [
    'driver' => 's3',
    'key'    => env('AWS_KEY'),
    'secret' => env('AWS_SECRET_KEY'),
    'region' => Aws\Common\Enum\Region::OREGON,
    'bucket' => 'app-images',
],

the regions can be found on the S3 GitHub Repo.

class Region extends Enum
{
    const US_EAST_1           = 'us-east-1';
    const VIRGINIA            = 'us-east-1';
    const NORTHERN_VIRGINIA   = 'us-east-1';
    const US_WEST_1           = 'us-west-1';
    const CALIFORNIA          = 'us-west-1';
    const NORTHERN_CALIFORNIA = 'us-west-1';
    const US_WEST_2           = 'us-west-2';
    const OREGON              = 'us-west-2';
    const EU_WEST_1           = 'eu-west-1';
    const IRELAND             = 'eu-west-1';
    const LONDON              = 'eu-west-2';

    const EU_CENTRAL_1        = 'eu-central-1';
    const FRANKFURT           = 'eu-central-1';
    const AP_SOUTHEAST_1      = 'ap-southeast-1';
    const SINGAPORE           = 'ap-southeast-1';
    const AP_SOUTHEAST_2      = 'ap-southeast-2';
    const SYDNEY              = 'ap-southeast-2';
    const AP_NORTHEAST_1      = 'ap-northeast-1';
    const TOKYO               = 'ap-northeast-1';
    const SA_EAST_1           = 'sa-east-1';
    const SAO_PAULO           = 'sa-east-1';
    const CN_NORTH_1          = 'cn-north-1';
    const BEIJING             = 'cn-north-1';
    const US_GOV_WEST_1       = 'us-gov-west-1';
    const GOV_CLOUD_US        = 'us-gov-west-1';
}

UPDATED PER COMMENT 5 YEARS LATER

Now my original approach works again. I forget when it started working, but there you go.

filesystems.php

's3' => [
    'driver' => 's3',
    'key'    => env('S3_KEY'),
    'secret' => env('S3_SECRET'),
    'region' => env('S3_REGION'),
    'bucket' => env('S3_BUCKET'),
],

.env

S3_REGION=us-east-1

It looks like they removed the Region.php file. Today, June 2020, the S3Client.php file is the only reference to regions I can find in their repo.

Truda answered 21/4, 2015 at 15:36 Comment(2)
i was having the same dam problem for like 2 hours & i have noooo idea why something like this is so hard to find ,so many many thanx for thisStipel
A3 GitHub Repo link is deadGravure

© 2022 - 2024 — McMap. All rights reserved.