7

Linode's Object Storage is marked as being S3 compatible. Knowing this I thought that I can simply use Linode's credentials in my filesystems.php and use ->disk('s3') to upload and download files but apparently this is not the case.

I have installed all required S3 PHP packages as suggested in Laravel's docs.

My .env has:

AWS_ACCESS_KEY_ID=foo
AWS_SECRET_ACCESS_KEY=bar
AWS_DEFAULT_REGION=DE
AWS_BUCKET=my-linode-storage-object.eu-central-1.linodeobjects.com

In logs I get exception to Could not resolve host. It tries to concatenate AWS endpoint with what I provided above so no-brainer that it doesn't work. Should I install completely different package to handle Linode's Storage Object connections?

I don't see much tutorials on the web on how to use Linode's Storage Object in Laravel apps. Any links or hints would be appreciated.

Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
  • Can't comment specific on Linode, but with your current approach your query will use AWS's S3 endpoint. Maybe have to overwrite it to use Linode endpoint? In boto3 you can use [endpoint_url](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) to overwrite the default enpoints used by boto3. PHP should have maybe something similar? – Marcin Apr 24 '20 at 11:18
  • I haven't heard of much about linode but I can give some advices. I think you should not hack your code. Your environment will look like using S3 except the host. Your code will also look like using S3. Additionally, you shouldn't put your credentials in your config files. Think like that you will just open your codebase to the public. Regards. – Onur Demir Apr 30 '20 at 11:33

1 Answers1

9

From the laravel docs just install one of the required Composer Packages

$ composer require league/flysystem-aws-s3-v3

Do not install league/flysystem-cached-adapter yet, since that would require more configuration.

Next, add a new disk that uses the s3 driver under the configuration filesytems file config/filesystems.php

'linode' => [
    'driver' => 's3',
    'key' => env('LINODE_KEY'),
    'secret' => env('LINODE_SECRET'),
    'endpoint' => env('LINODE_ENDPOINT'),
    'region' => env('LINODE_REGION'),
    'bucket' => env('LINODE_BUCKET'),
],

Add the new the environment variables to your project's .env file:

LINODE_KEY="KEYUNDERDOUBLEQUOTES"
LINODE_SECRET="SECRETUNDERDOUBLEQUOTES"
LINODE_ENDPOINT="https://eu-central-1.linodeobjects.com"
LINODE_REGION="eu-central-1"
LINODE_BUCKET="bucket-name"

I usually include the variables under "" to make sure it works with symbols. Also include http or https under LINODE_ENDPOINT.

Now that you have everything set up, you can now use this disk on your laravel code ->disk('linode')

charlfields
  • 351
  • 3
  • 6
  • 1
    Thanks @charlfields! I was struggling to find the correct format for the specific fields, but your post helped me. – Savlon Jul 11 '21 at 08:26