Laravel Driver error - Driver [] is not supported - php

Anyone else had this issue:
I set my filesystems.php config defualt from local to cloud (which is set to my s3) and I get this error with my storage code:
$path = $request->file('avatar')->store('avatars'); -> in my UserController
Error : Driver [] is not supported.
If I leave the filesystems config to stock and just run this code the image uploads to my s3 fine
$path = $request->file('avatar')->store('avatars', 's3'); -> in my UserController
shouldnt $path = $request->file('avatar')->store('avatars'); run to what ever the default is without passing the specific driver? I tried 'default' => 's3', and that gets the same error
CONFIG DRIVERS
'default' => 'local',
'cloud' => 's3',
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],

I guess, that whether your example with manually typing a storage to the store() function works well, you can have a problem with storage config.
Could you, please, show your configuration file with storage types?

Related

Image source not readable when trying to load images that are stored on S3 in laravel 5.2

I am trying to run a copy of a website locally but for some reason none of the images work. They are stored on an S3 bucket.
In my config/filesystems.php the default is s3:
'default' => 's3',
My keys are the same as on the live site:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID', 'key'),
'secret' => env('AWS_SECRET_ACCESS_KEY', 'key'),
'region' => 'eu-central-1',
'bucket' => 'storage.website.nl',
'cloud' => 'cloud.website.nl'
],
],
The only difference is my storage/app does not have a public folder with all the media in it like on the live site. But this should be created I think with something similar like php artisan storage:link except this command does not work in laravel 5.2.
What can I do to fix that?

laravel file upload on a project on a hosted project

I have hosted my laravel application, before this file uploads and everything was working fine, but after I put it on cpanel, File uploading is nolonger working.
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
this is my code, may someone help. in my .env file I inserted my app url for the website which is working file except for file upload
Regards

laravel5 create custom disk for uploading photo

I'm using laravel 5.6 and i wanted to create my custom disk for uploading images
and i received this error
InvalidArgumentException Driver [] is not supported.
this is how i save file in controller
$cover = $request->file('cover_image');
$extension = $cover->getClientOriginalExtension();
Storage::disk('test')->put($cover->getFilename().'.'.$extension, File::get($cover));
this is my config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'test' => [
'driver' => 'local',
'root' => storage_path(),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public/asghar'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
the error occurred because my configuration was cached.
probably I accidentally used config:cache or sth similar.
the issue resolved by clearing the config cache using this command
php artisan config:clear

Storage::get() results in a FileNotFoundException

I'm trying to load a external JSON file into my laravel application. Below you will find a snippet of my code.
$location = __DIR__.'/config.json';
echo $location; // Results in correct file location
echo File::exists($location); // Return 1
echo Storage::get($location); // Throws a FileNotFound Exception
How can the File::exists() method return true and the Storage::get() throw an exception?
My config/filesystems.php file:
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
Why use the Storage class for this? That class is specifically for accessing the storage folder or external file servers. You stored your file right next to your controller/code, so it's probably easier to do it the old-fashioned way.
$location = __DIR__.'/config.json';
if (File::exists($location)) {
$string = file_get_contents($location);
$json = json_decode($string, true);
// logic
} else {
// Do something
}
You can try accessing it through the file facade by
File::get($location);
The error is probably because Storage is trying to access the file from its default path (./project/storage/app) plus what you send it. My best advice, is to add a new disk
like this
// config/filesystems.php
'customDrive' => [
'driver' => 'local',
'root' => base_path(), // here put your full path
],
and acess it through
Storage::disk("customDrive")->get("config.json");
Source https://laravel.com/docs/5.6/filesystem

Storage path set using .env in Laravel 5.1

I want to configure the storage path in a Laravel 5.1 using the .env file. My bootstrap/app.php looks like this:
<?php
$app = new \Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
$app->useStoragePath(getenv('STORAGE_PATH'));
and the relevant line in .env file is:
STORAGE_PATH=/var/www/storage
This doesn't work. I figured out the Dotenv library is initialised after the bootstrap is processed so the .env variables are not available in bootstrap.php.
Is there a different place where I can set the storage path and the .env variables are available?
In config/filesystems.php you can set your storage path. Try setting your storage path there and see if it works. Note that the example below is my suggestion as to how your config/filesystems.php should look. Don't mind the s3 setup. That's a part of my project.
Remember to remove $app->useStoragePath(getenv('STORAGE_PATH')); from app.php
return [
'default' => 's3',
'cloud' => 's3',
'disks' => [
'local' => [
'driver' => 'local',
'root' => env('STORAGE_PATH'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'rackspace' => [
'driver' => 'rackspace',
'username' => 'your-username',
'key' => 'your-key',
'container' => 'your-container',
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
'region' => 'IAD',
],
],
];

Categories