Closed loranger closed 7 years ago
If you haven't specified an custom url generator in the config file, the package will try to find an url generator for the driver of the disk the media is stored upon. That happens here: https://github.com/spatie/laravel-medialibrary/blob/19b4d5c36b567926e14fdef591f8d7388933f035/src/UrlGenerator/UrlGeneratorFactory.php#L14
Which disk driver are you using? What the value of disk
in the media table?
Thanks for your help
I have a custom url generator (the same I use with Laravel: I'm trying to my project api from Laravel to Lumen, without loosing any feature) and a custom path generator.
Here is my laravel-medialibrary.php
configuration file :
<?php
return [
/*
* The filesystems on which to store added files and derived images by default. Choose
* one or more of the filesystems you configured in app/config/filesystems.php
*/
'defaultFilesystem' => 'media',
/*
* The maximum file size of an item in bytes. Adding a file
* that is larger will result in an exception.
*/
'max_file_size' => 1024 * 1024 * 20,
/*
* This queue will used to generate derived images.
* Leave empty to use the default queue.
*/
'queue_name' => '',
/*
* The class name of the media model to be used.
*/
'media_model' => Spatie\MediaLibrary\Media::class,
/*
* When urls to files get generated this class will be called. Leave empty
* if your files are stored locally above the site root or on s3.
*/
'custom_url_generator_class' => App\Services\MediaLibraryUrlGenerator::class,
/*
* The class that contains the strategy for determining a media file's path.
*/
'custom_path_generator_class' => App\Services\MediaPathGenerator::class,
's3' => [
/*
* The domain that should be prepended when generating urls.
*/
'domain' => 'https://xxxxxxx.s3.amazonaws.com',
],
'remote' => [
/*
* Any extra headers that should be included when uploading media to
* a remote disk. Even though supported headers may vary between
* different drivers, a sensible default has been provided.
*
* Supported by S3: CacheControl, Expires, StorageClass,
* ServerSideEncryption, Metadata, ACL, ContentEncoding
*/
'extra_headers' => [
'CacheControl' => 'max-age=604800',
],
],
];
and here is my filsystems.php
file :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => 'local',
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => 's3',
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "s3", "rackspace"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'media' => [
'driver' => 'local',
'root' => public_path('media'),
],
],
];
They are exactly the same as the ones working with Laravel. Maybe I did miss a namepsace conversion or something ?
@loranger Having the same error. Did you manage to solve anything?
@loranger not sure if this is your case, but does your custom App\Services\MediaLibraryUrlGenerator
correctly implements Spatie\MediaLibrary\UrlGenerator\UrlGenerator
interface?
You can also try instead of implementing the interface, to extend the Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator
Please have a the docs as well
@kickthemooon @iraklisg I didn't find any way to resolve this issue and also had trouble to use the same User object with both Lumen and Laravel, so I dropped my lumen api and use Laravel only :/
I have the same issue and i'm not using Lumen.
I am using v6.6.2 with Laravel 5.5 and cannot get this issue resolved.
For those who comes here. My solution: check that your filesystems.php has configurations for 'disk_name' from medialibrary.php config file. Because media library relies on the value of disk_name and tries to create {DiskName}UrlGenerator class that probably doesn't exist.
Cheers!
I got similar message, and after spending 1/2 a day i found out that my value in the media table under "disk" in the database had to match that of the value of your disk in your medialibray.php configuration file.
The error was misleading since it say that "Class Spatie\MediaLibrary\UrlGenerator\UrlGenerator doesn't exist"
In my case i had to change all the values in my table under the 'disk' field to media.
Hello,
I try to use my existing Laravel Models (already using media-library) inside a Lumen project. I setup laravel-medialibrary for lumen as written in the documentation. Everything seems to work perfectly, but as soon as I try to get a
$media->getUrl()
, I get this exception :Can you help me to figure out what is my mistake ?