F
Filament5mo ago
Liam

SpatieMediaLibrary plugin CORS issue@

Hi everyone I'm using Spatie's Media Library to manage my images in Filament. I did setup an S3 bucket with the following CORS policy:
[
{
"AllowedHeaders": [],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
[
{
"AllowedHeaders": [],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
` When I upload an image in Filament I still get a CORS issue. How can I solve this?
19 Replies
DrByte
DrByte5mo ago
This is how I usually configure it. (I don't like using * in the AllowedOrigins, so I put both my production URL and local-testing URL, unless I'm using separate buckets for those separate purposes, in which case I put the specific URL instead).
No description
Liam
Liam5mo ago
I see, but what I have should work no? I did setup it in my env like this: FILESYSTEM_DISK=s3 FILAMENT_FILESYSTEM_DISK=s3
Liam
Liam5mo ago
I get an error when it tries to upload it to the livewire-tmp folder
No description
DrByte
DrByte5mo ago
Have you tried specifically adding your .be domain to the AWS AllowedOrigins array?
Liam
Liam5mo ago
I'll try that now, getting
Disk named `media` cannot be accessed
Disk named `media` cannot be accessed
error now. But I also changed my FILESYSTEM_DISK to local again and specific ->disk('media') on the form element now.
awcodes
awcodes5mo ago
Local disk cannot be accessed like this. Change disk to public. s3 should be fine as long as your s3 permissions are set up correctly.
Liam
Liam5mo ago
It is set as public
Liam
Liam5mo ago
No description
Liam
Liam5mo ago
I'm just really confused, I don't need to add
visibility('private')
visibility('private')
on the form element right? I just want to upload these images on my public bucket.
awcodes
awcodes5mo ago
You may still need it. Iirc there’s a caveat with s3 uploads if the livewire temp folder isn’t also set to s3.
Liam
Liam5mo ago
Preferably I want the livewire-tmp folder to be on the bucket too but it doesn't work and its related to this I believe: https://github.com/filamentphp/filament/discussions/4483
GitHub
S3 cors · filamentphp filament · Discussion #4483
Local and remote same problem, added bucket Cors config: [ { "AllowedHeaders": [ "Authorization" ], "AllowedMethods": [ "GET", "HEAD", "PUT&qu...
awcodes
awcodes5mo ago
If you change the tmp directory in the livewire config I would expect it all to work correctly.
Liam
Liam5mo ago
Aha, didn't try that yet. Will give it a try
awcodes
awcodes5mo ago
Again, depending on the bucket being configured correctly on the Aws side.
Liam
Liam5mo ago
That should be all good. Thanks for the tip 🙂
awcodes
awcodes5mo ago
I don’t use Aws though. So my help here is limited.
Liam
Liam5mo ago
Didn't work unfortunately.. Will take a break from it for now haha
awcodes
awcodes5mo ago
Always a good idea.
Liam
Liam5mo ago
Ok fixed the CORS issue. I took the example from AWS again, replaced it with my data and it works now. But now I am still stuck with the Spatie Library not able to access my media disk in my flysystem config Deleting
'visibility' => 'public'
'visibility' => 'public'
fixes it but I don't get why. Isn't that the purpose of the Spatie Media Library to have files uploaded to S3 which are publicly accessed?