I have a Content Distribution Network served by AWS CloudFront.
Some of my clients want to download this file with a specific filename, so I guess that the natural solution will be injecting a Content-Disposition response header.
For example, I can use a query parameter filename for my CloudFront URL so that this file can be downloaded with the name awesome.png
https://XXX.cloudfront.net/abc.png?filename=awesome.png
Then all I have to do is to add the Content-Disposition header to its response.
I thought that it can be easily handled by CloudFront Function or Lambda#Edge, but I found that they cannot solve my problem. It's because the query string filename is in the HTTP request, but the Content-Disposition header must be injected in the HTTP header.
Can anyone suggest a working solution?
Related
I'm using AWS S3 and CloudFront to distribute content.
My files stored in S3 have binary/octet-stream type but in fact they can be images or documents.
When generating S3 URLs, I can override the response content type with a parameter like this: https://my-bucket.s3.eu-central-1.amazonaws.com/foo/bar?[...]&response-content-type=image/jpeg
Is there a way to do it with CloudFront (with the same S3 bucket as origin)?
I tried adding the same parameter -- it's ignored.
I can create a response headers policy and add a custom header overriding origin, but as far as I can see, it'll be the same for all files whereas I need to control it with a request parameter.
I try to upload gif to AWS S3. URL is presigned. For presign I use Vapor for sending image it happens from React.
Here docs says: https://soto.codes/2020/12/presigned-urls.html
If you want to include some headers values with the URL you have to include the headers while signing it and the client will be required to include exactly the same headers when they use the URL.
but image/gif is sent at presign. In the return of presign I see X-Amz-SignedHeaders: content-type%3Bhost%3Bx-amz-acl.
Seems presign did his part.
Then the content upload, with PUT has also has the Content-Type: image/gif
Then what is wrong. Why S3 does not have the type?
No type here:
Just realised you are looking at the wrong thing. Scroll further down on the aws console page until you find the metadata section. You can also test this by running a get on the object and see what content-type is returned
How can we remove the download option for any video/mp4 when we try to access signed url generated in cloudFront ?
Is there a way to set Request Headers in GetObject Request either through Bucket Policy update or Lambda#Edge to pre-check if the header is present in the url get request or not before allowing the user to access the url in browser ?
It seems unclear form the docs, but here is my goal:
Create a presigned url to upload a file to s3
Pass that url to the browser
The browser uploads a file selected by the user to s3 using the pre-signed url
When the object on s3 is requested, the "Cache-Control: max-age=604800" header is on the response.
I would LIKE to not have to rely on the client to do anything special to make this happen. Meaning, some signal to S3 that it should set the cache control header to that value would have to be present in the pre-signed url, but I can't tell from the docs or 50 google searches how that is accomplished.
Any illumination into how this can be accomplished would be great!
We have uploaded an mp4 video file into our Magnolia DMS, which fails to play on Safari (Mac/iPad). Investigation shows that the Content-Type returned by Magnolia is "application/octet-stream" for the request. When serving the file through Tomcat directly, the correct Content-Type "video/mp4" is returned and video playback works.
How can we configure the content-type to be returned in Magnolia?
We know the content-type is a function of the request (e.g. if we add ".jpg" to the URL the type returned is "image/jpeg"), but couldn't use this knowledge to come up with a solution.
Update:
We found the MIME configuration and could change the Content-Type for "mp4" to "video/mp4". However, the Content-Type returned by Magnolia is now
Content-Type: video/mp4;charset=UTF-8
while the correct, working Content-Type returned for files hosted by Tomcat is
Content-Type: video/mp4
Is it possible to make Magnolia not append any charset info to the Content-Type?
Glad you found the MIME configuration OK.
Both the MIME type and the character encoding are set in ContentTypeFilter.java and MIMEMapping.java. You can specify a charset for a MIME type yourself by including it in the mime-type definition. (E.g. "video/mp4;charset=UTF-8".)
If you don't include one, however, Magnolia automatically assigns the default (in this case, UTF-8). If you want to change this behavior, you'd need to tweak the source code.
Out of curiosity, is the charset causing you any trouble, or are you just trying to get Magnolia to match what Tomcat does by default?