FileUpload with url
I am uploading my images using a service and it is working fine, But 😦
How can the FileUpload field show a file via url
this gives the right url
Solution:Jump to solution
I added the CORS middleware to my FastAPI service and it is working
Last question
When I want to edit the resource, the image dose not appear...
10 Replies
When the upload finishes
It tries to get the image from here
http://localhost/storage/WDg6gQRYyncjVtefyTC7WGZxrAKUNK-metaU2NyZWVuc2hvdCAyMDIzLTA4LTI0IDE0Mjg0MS5wbmc=-.png
but the right URL is
http://localhost:8088/uploads/lYNXDISVmx.png
I can not configure a disk because I only need an HTTP request
I asked if I could configure a disk with just A URL in the Laravel Discoed server
Their answer was:
Then that’s not a disk.
The Storage facade and disks are an abstraction layer for filesystems. Not for making HTTP requests.
Use the HTTP client to make HTTP requests: https://laravel.com/docs/10.x/http-client
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Any help please
I'm not sure the FileUpload field was designed to work that way...
What is the image upload service you're using, can you give a bit more context?
I am using my own FastAPI server to handle image saving, creating thumbnails and selecting the storage
Ok, I'm not familiar with this service. Does the image upload work correctly? The issue is just displaying the image after it's uploaded?
Yes the image upload work correctly
Yes The issue is just displaying the image after it's uploaded
I Almost find the solution
but now I am getting this error
Access to fetch at 'http://127.0.0.1:8088/uploads/CshuuKhfkY.png' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Have a look at
config/cors.php
, I think you can add an exception for a known domain (ie. your other app's port):
https://laravel.com/docs/10.x/routing#corsLaravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
I think the problem here is that you don’t have a filesystem driver for you custom disk. So the storage facade doesn’t know how to construct a urll for it.
Solution
I added the CORS middleware to my FastAPI service and it is working
Last question
When I want to edit the resource, the image dose not appear
I created A custom field (ShowImage) to show the image via URL
Is there a way to display the image inside the FileUpload field without a disk
The FileUpload field is strongly coupled with the Laravel storage facade that's why I have this issue from the beginning
Or my problem is a very specific edge case
Is there a way to display the image inside the FileUpload field without a diskI'm not sure... I've never implemented something like this. But the idea of the
ShowImage
component sounds like a good and simple solution.