Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later. Yes No. Upload file. Any help would be greatly appreciated. Amazon has now solved this problem and allows overriding of headers on a per-request basis with signed requests:.
The php scripts that have been mentioned so far will work ok, but the main downside is that every time a visitor on your site requests a file, your own servers will load it from the S3 and then relay that data to the browser. For low traffic sites, it's probably not a big deal, but for high traffic ones, you definitely want to avoid running everything through your own servers.
Luckily, there's a fairly straight-forward way to set your files to be forced to download from the S3. And you're exactly right - you just want to set the content-type and content-disposition just setting content-disposition will work in some browsers, but setting both should work in all browsers. Now all your files will be forced to download. You may need to clear your cache to see the change. And obviously, don't do that on any file that you actually do want to be loaded "inline" in the browser.
The nice part with this solution is that applications that load media files directly like let's say an mp3 player in Flash don't care about the content-type or content-disposition, so you can still play your files in the browser and then link to download that same file.
If the user already finished loading the file in flash, they'll most likely still have it in their cache, which means their download will be super quick and it won't even cost you any extra bandwidth charges from the S3. Now you will want to put some validation in there so that you not giving the world access to every file you put on S3, but this should work.
If you are using a library like Tarzan AWS , you can add meta headers, that amazon will include when the file is retrieved. Also worth mentioning is you are able to hard-set the headers for files in S3.
For example, if you need to force-download a certain file you can set the appropriate headers for that file. To get that client behaviour, you have to get the client to request the file based on the web page's html or javascript. So you have to get the client to download the file. For instance, have an iframe on the page with the url of the file on s3.
Use css to make the iframe invisible. It should render the page and download and play the mp3. Otherwise, look into using javascript to kick of a download when the page loads. I'm not sure if that's possible. There are times when you want to override certain response header values in a GET response.
You can override values for a set of response headers using the query parameters listed in the following table. You must sign the request, either using an Authorization header or a pre-signed URL, when using these parameters. They cannot be used with an unsigned anonymous request.
I never tried Amazon's S3 hosting, but don't you have access to using. Then you can set Content-Type and Content-Disposition for an entire directory with this entry:.
Otherwise, look into using javascript to kick of a download when the page loads. There are times when you want to override certain response header values in a GET response.
You can override values for a set of response headers using the query parameters listed in the following table. You must sign the request, either using an Authorization header or a pre-signed URL, when using these parameters. They cannot be used with an unsigned anonymous request.
Then you can set Content-Type and Content-Disposition for an entire directory with this entry:. December 2, Php Leave a comment. The strange thing is that the form always used to process th Add menu.
0コメント