I'm creating a new topic because I'm not getting any further on my following posts and I'm pretty frustrated:
I'm hoping for someone with another idea.
I tried using IONOS, Amazon AWS and Digital Ocean with the recommended CORS settings from @Teodor, but I always get the same CORS errors with the Download Component.
I just need to download the PDF files directly instead of opening in a new browser tab. Does someone have another idea how to do this and got this working?
I updated my test-website https://www.***.de with aws and Digital Ocean. CORS set like recommended. Download still opens in Browser instead of direct download.
I need to go live with my updated website with S3 integration and really need a solution for this. Any hint what I could do?
In both cases it fails the cors check and I also donāt see any cors headers in the response.
Iāve made a small change in the download component to handle filenames, please check if it helps to prevent the file being opened in the browser. Since the cors fails it will still use the browser download and not using xhr, so a progress can not be tracked, but it should not open it in the browser.
Thank you for the updated file. It doesnāt make a difference.
What I tried with aws is to add HEAD in the CORS JSON. It doesnāt show the CORS error anymore. But this is only for aws. With other providers it does not work.
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD
Access-Control-Allow-Origin: *
But the server returns status 403.
With Digital Ocean it returns no cors headers and is getting a cors error. I use the same cors configuration in my tests, only the Access Control Max Age is higher.
It seems that the fallback doesnāt work in chrome, again is cors the reason for this. It seems that they decided that when a file comes from an other domain then they will ignore the download property of a link. The link will then be opened in a normal way, so the pdf will be handled as default and opened in the browser.
Workaround you can test is setting Content-Type or/and Content-Disposition. On Digital Ocean you can change them with Manage Metadata. Set Content-Disposition to attachment.
The workaround for Digital Ocean does work for the test file. My problem is that I have over 100.000 files in my S3 bucket . How do I change them? Could it be possible to change the signed URL or can I set it on upload?
I checked the API and it is possible to set all this when uploading the file, but it is not available in the server connect action, there we only have the most common used properties added. Will see if we could perhaps add some extra properties. What server model (Node/PHP) do you use? Then I will post an update here when I have one.
The workaround is using creating an a tag with an download attribute to do the download, seems that the download attribute also require CORS but donāt give an error, it then just opens the link in a normal way instead of downloading.
So the only way for you when you canāt get CORS working is setting the correct headers for the file. Will try to post an update for you here today for that.
No, I donāt have CDN enabled. I already looked at this post from stackoverflow on my search after a solution for my CORS problem. Did you get CORS working in your tests?
Here the updated s3 library. You have to edit the action file by hand since the new options are not available in the UI. Unzip the file in lib/modules.
The putFile action has contentType and contentDisposition as extra options, default it will detect the contentType automatically by the file extension. Here my example:
I also added a new action to the s3 module, it will allow you to download the file using the server action, this works around the CORS problem. You then use the server connect url instead of the s3 url in the download component.