GeorgeKala's avatar

Laravel DigitalOcean Spaces Upload Issue

Hi everyone,

I'm currently working on a Laravel application where I need to upload files to DigitalOcean Spaces. I've set up my spaces disk in config/filesystems.php as follows:

'spaces' => [ 'driver' => 's3', 'key' => env('DO_ACCESS_KEY_ID'), 'secret' => env('DO_SECRET_ACCESS_KEY'), 'endpoint' => env('DO_ENDPOINT'), 'region' => env('DO_DEFAULT_REGION'), 'bucket' => env('DO_BUCKET'), 'visibility' => 'public', ], Here's the controller method I'm using for the upload:

`` public function upload(Request $request) { $request->validate([ 'file' => 'required|file|max:2048', 'directory' => 'nullable|string', ]);

try {
    $file = $request->file('file');
    $directory = $request->input('directory', 'uploads');
    $directory = trim($directory) !== '' ? $directory : 'uploads';

    $filePath = $file->store($directory, ['disk' => 'spaces', 'visibility' => 'public']);

    if (!$filePath) {
        throw new \Exception('The store method did not return a valid path.');
    }

    $fileUrl = Storage::disk('spaces')->url($filePath);

    Log::info('File uploaded successfully', [
        'file_path' => $filePath,
        'file_url' => $fileUrl,
    ]);

    return response()->json(['url' => $fileUrl, 'path' => $filePath], 201);
} catch (\Throwable $e) {
    Log::error('File upload failed with error', [
        'exception_message' => $e->getMessage(),
        'trace' => $e->getTraceAsString(),
        'disk_config' => config('filesystems.disks.spaces'),
    ]);

    return response()->json([
        'error' => 'File upload failed',
        'message' => $e->getMessage(),
    ], 500);
}

}

`` The problem is that:

  • No file is uploaded.
  • No folder is created in the specified Space.
  • I don't see any errors logged, even in storage/logs/laravel.log.

I've tested the configuration, and it seems correct. The store method returns null, but I can't figure out why. I've double-checked the following:

  • My access key and secret key are correct.
  • The Space has write permissions.

Questions:

  • Has anyone faced a similar issue where no file or folder is created, and no error is shown?
  • Could this be related to a misconfiguration in the spaces disk?
  • Is there a way to debug this further or force Laravel to give more detailed error messages?

Any help or guidance would be greatly appreciated. Thank you in advance!

0 likes
1 reply
aprilnieves's avatar

Hello, I got the same issue. I think a misconfiguration in the Spaces disk could definitely be the cause of your issues. You should make sure that Laravel's debug mode is enabled. You can do this by setting the following in your .env file:

dotenv APP_DEBUG=true

With this setting, Laravel will show detailed error messages instead of generic ones. Remember to turn this off in a production environment.

Please or to participate in this conversation.