Home > Back-end >  Laravel 8 and Digitalocean spaces storage upload
Laravel 8 and Digitalocean spaces storage upload

Time:10-06

Anyone did success for upload to Digitalocean spaces for laravel 8

here is my composer

"laravel/framework": "^8.54",
"league/flysystem-aws-s3-v3": "^1.0",

in filesystems.php

'spaces' => [
   'driver' => 's3',
   'key' => env('SPACES_ACCESS_KEY_ID', '===AAACESS KEY==='),
   'secret' => env('SPACES_SECRET_ACCESS_KEY', '===BBBSECRECT KEY==='),
   'region' => env('SPACES_DEFAULT_REGION', 'sgp1'),
   'bucket' => env('SPACES_BUCKET', 'laravel-spaces'),
   'url' => env('SPACES_URL', 'https://laravel-spaces.sgp1.cdn.digitaloceanspaces.com'),
   'endpoint' => env('SPACES_ENDPOINT', 'https://sgp1.digitaloceanspaces.com')
],

Tinker upload test

$path = 'thumb.png';
$file = Storage::disk('spaces')->put($path, @file_get_contents(public_path('images/logo.png')));

Errors

Aws\S3\Exception\S3Exception with message 'Error executing "PutObject" on "https://laravel-spaces.s3.sgp1.amazonaws.com/thumb.png"; AWS HTTP error: cURL error 6: Could not resolve: laravel-spaces.s3.sgp1.amazonaws.com (Domain name not found) (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://laravel-spaces.s3.sgp1.amazonaws.com/thumb.png'
*** Execution finished ***
                              

Why append s3 and amazonaws.com to url

And how to solve this

Thanks.

CodePudding user response:

Thanks all for help. I am solved problem, problem by .env file config wrong.

this is right config

SPACES_ACCESS_KEY_ID=AAAAA
SPACES_SECRET_ACCESS_KEY=BBBB
SPACES_DEFAULT_REGION=sgp1
SPACES_BUCKET=mybucket
SPACES_ENDPOINT=https://mybucket.sgp1.digitaloceanspaces.com
SPACES_URL=https://mybucket.sgp1.cdn.digitaloceanspaces.com

And Config

'spaces' => [
  'driver' => 's3',
  'key' => env('SPACES_ACCESS_KEY_ID'),
  'secret' => env('SPACES_SECRET_ACCESS_KEY'),
  'region' => env('SPACES_DEFAULT_REGION'),
  'bucket' => env('SPACES_BUCKET'),
  'url' => env('SPACES_URL'),
  'endpoint' => env('SPACES_ENDPOINT'),
  'bucket_endpoint' => true,
  'visibility' => 'public',
],

CodePudding user response:

Your error is telling you exactly what the issue is

Aws\S3\Exception\S3Exception with message 'Error executing "PutObject" on "https://laravel-spaces.s3.sgp1.amazonaws.com/thumb.png"; AWS HTTP error: cURL error 6: Could not resolve: laravel-spaces.s3.sgp1.amazonaws.com (Domain name not found) (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://laravel-spaces.s3.sgp1.amazonaws.com/thumb.png'
*** Execution finished ***

It cannot resolve sgp1.amazonaws.com - this means there is something missing inside your ENV file. Without seeing the env file I could not tell you.

That being said, I get what you are trying to do inside filesystems.php - but you should set all variables inside ENV regardless of what you set the fallback to

  • Related