laravel-mediable
laravel-mediable copied to clipboard
Cannot upload to S3, no errors.
I cannot upload a file to S3. S3 is configured correctly as this does work:
Storage::disk('s3')->put('uploads', $request->file('image'));
But this does not work (and no error message either):
MediaUploader::fromSource($request->file('image'))->toDisk('s3')->upload();
Also note, this does work when uploading locally.
Config:
<?php
return [
/*
* FQCN of the model to use for media
*
* Should extend `Plank\Mediable\Media`
*/
'model' => App\Models\Media::class,
/*
* Name to be used for mediables joining table
*/
'mediables_table' => 'mediables',
/*
* Filesystem disk to use if none is specified
*/
'default_disk' => 's3',
/*
* Filesystems that can be used for media storage
*
* Uploader will throw an exception if a disk not in this list is selected
*/
'allowed_disks' => [
'public',
's3',
],
/*
* The maximum file size in bytes for a single uploaded file
*/
'max_size' => 1024 * 1024 * 8,
/*
* What to do if a duplicate file is uploaded.
*
* Options include:
*
* * `'increment'`: the new file's name is given an incrementing suffix
* * `'replace'` : the old file and media model is deleted
* * `'error'`: an Exception is thrown
*/
'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_ERROR,
/*
* Reject files unless both their mime and extension are recognized and both match a single aggregate type
*/
'strict_type_checking' => false,
/*
* Reject files whose mime type or extension is not recognized
* if true, files will be given a type of `'other'`
*/
'allow_unrecognized_types' => false,
/*
* Only allow files with specific MIME type(s) to be uploaded
*/
'allowed_mime_types' => [],
/*
* Only allow files with specific file extension(s) to be uploaded
*/
'allowed_extensions' => [],
/*
* Only allow files matching specific aggregate type(s) to be uploaded
*/
'allowed_aggregate_types' => [
Plank\Mediable\Media::TYPE_IMAGE,
],
/*
* List of aggregate types recognized by the application
*
* Each type should list the MIME types and extensions
* that should be recognized for the type
*/
'aggregate_types' => [
Plank\Mediable\Media::TYPE_IMAGE => [
'mime_types' => [
'image/jpeg',
'image/png',
'image/gif',
],
'extensions' => [
'jpg',
'jpeg',
'png',
'gif',
]
],
Plank\Mediable\Media::TYPE_IMAGE_VECTOR => [
'mime_types' => [
'image/svg+xml',
],
'extensions' => [
'svg',
]
],
Plank\Mediable\Media::TYPE_PDF => [
'mime_types' => [
'application/pdf',
],
'extensions' => [
'pdf',
]
],
Plank\Mediable\Media::TYPE_AUDIO => [
'mime_types' => [
'audio/aac',
'audio/ogg',
'audio/mpeg',
'audio/mp3',
'audio/mpeg',
'audio/wav'
],
'extensions' => [
'aac',
'ogg',
'oga',
'mp3',
'wav',
]
],
Plank\Mediable\Media::TYPE_VIDEO => [
'mime_types' => [
'video/mp4',
'video/mpeg',
'video/ogg',
'video/webm'
],
'extensions' => [
'mp4',
'm4v',
'mov',
'ogv',
'webm'
]
],
Plank\Mediable\Media::TYPE_ARCHIVE => [
'mime_types' => [
'application/zip',
'application/x-compressed-zip',
'multipart/x-zip',
],
'extensions' => [
'zip',
]
],
Plank\Mediable\Media::TYPE_DOCUMENT => [
'mime_types' => [
'text/plain',
'application/plain',
'text/xml',
'text/json',
'application/json',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
],
'extensions' => [
'doc',
'docx',
'txt',
'text',
'xml',
'json',
]
],
Plank\Mediable\Media::TYPE_SPREADSHEET => [
'mime_types' => [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
'extensions' => [
'xls',
'xlsx',
]
],
Plank\Mediable\Media::TYPE_PRESENTATION => [
'mime_types' =>
[
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow'
],
'extensions' =>
[
'ppt',
'pptx',
'ppsx',
]
],
],
/*
* List of adapters to use for various source inputs
*
* Adapters can map either to a class or a pattern (regex)
*/
'source_adapters' => [
'class' => [
Symfony\Component\HttpFoundation\File\UploadedFile::class => Plank\Mediable\SourceAdapters\UploadedFileAdapter::class,
Symfony\Component\HttpFoundation\File\File::class => Plank\Mediable\SourceAdapters\FileAdapter::class,
Psr\Http\Message\StreamInterface::class => Plank\Mediable\SourceAdapters\StreamAdapter::class,
],
'pattern' => [
'^https?://' => Plank\Mediable\SourceAdapters\RemoteUrlAdapter::class,
'^/' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class,
'^[a-zA-Z]:\\\\' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class
],
],
/*
* List of URL Generators to use for handling various filesystem drivers
*
*/
'url_generators' => [
'local' => Plank\Mediable\UrlGenerators\LocalUrlGenerator::class,
's3' => Plank\Mediable\UrlGenerators\S3UrlGenerator::class,
],
/**
* Should mediable instances automatically reload their media relationships after modification are made to a tag.
*
* If true, will automatically reload media the next time `getMedia()`, `getMediaMatchAll()` or `getAllMediaByTag()` are called.
*/
'rehydrate_media' => true,
/**
* Detach associated media when mediable model is soft deleted.
*/
'detach_on_soft_delete' => false,
/**
* Variant sizes.
*/
'variants' => [
'x-small' => 500,
'small' => 750,
'medium' => 1000,
'large' => 1500,
'x-large' => 2000,
]
];
what is the configuration of your disks?
@frasmage
I tried this ->makePrivate()
and it now works.
The bucket on S3 is private (as it's accessed through cloudfront).
So - does a private S3 bucket need the ->makePrivate()
method? Is there a way to set this in the config?
Here's the disk config anyway:
<?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' => env('FILESYSTEM_DISK', 'local'),
/*
|--------------------------------------------------------------------------
| 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", "sftp", "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'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
],
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
public_path('storage') => storage_path('app/public'),
],
];
Not sure why it wouldn't work with public visibility specified. But if your bucket is configured to only be accessible privately, then matching the file visibility makes sense. You can make the bucket default to private visibility by adding 'visibility' => 'private'
to the s3 disk config.
@frasmage I've added 'visibility' => 'private'
to the S3 config but it seems this setting is not taken into account, I have cleared the config cache too.
After browsing the code it seems like public
is defaulted to in the MediaUploader class:
https://github.com/plank/laravel-mediable/blob/master/src/MediaUploader.php#L82
And the only way to override it is to use the makePublic()
and makePrivate
methods or by passing options
.
Unless I am missing something?