s3_website setting MIME type for files without extension using - amazon-s3

I'm trying to deploy a Jekyll site. Here's the flow:
Content is added and pushed to BitBucket
BitBucket Pipelines builds the site
Finds all HTML files in _site/ and removes their extension
Uses s3_website push (s3_website) to push contents to the designated S3 bucket
I'm removing the extension from the HTML files since I need clean URLs. Although, there's an additional step required to set the MIME type on these files to ensure S3 serves them correctly.
Somehow, the MIME type is being detected by itself as of now, and the site works, but I'm uncomfortable not having control over it. So, I tried to add the following to s3_website.yml to set the MIME type:
content_type:
"*": text/html
But that breaks the site.
How do I set s3_website to pick only those files that do not have an extension, and set the MIME type only to them?

The site would work without setting the MIME type, if Tika is able to correctly detect the content type by itself.
In case users need more control over this, the s3_website gem includes a YAML configuration that can handle this version 1.15.0.
Add this to s3_website.yml:
extensionless_mime_type: text/html
This sets the MIME type for all files that don't have an extension, to text/html.

Related

uncompress gzipped assets with custom extension in browser

We want to serve gzipped files to the browser and it seems to be working with common file extensions such as css, txt, js etc.
However, when we change the extension to something else for e.g. filename.abc browser does not uncompress gzipped file even though Content-Encoding header is gzip. We have tried various combinations with Content-Type header.
How can we keep the custom extension of a file (say .abc) and still have browsers uncompress gzipped file automatically based on header info?
We were adding Content-Encoding, Content-Type headers via AWS cli s3 cp --metadata option. Setting it with --content-encoding and --content-type worked fine.

How to serve a static html that has a php extension with S3?

I can't change the extension of the file, but I need to serve it as a html file. No php inside.
That will work fine. Set the Content-Type to text/html.
You can do this in the S3 console, described in How do I add metadata to an S3 object? or when you initially upload the file.

Is there a way to reupload a file to S3 without having to reset a custom MIME type?

I have two xml files that need (or really want) to be served with specific MIME types that S3 doesn't serve by default. The files are sitemap.xml and rss.xml served as application/xml and application/rss+xml respectively.
I am able to set the Content-Type header for these files no problem.
The problem is every time my site changes these files change. I should say that my site is completely static from a web server perspective. My site is updated by me building the files locally and uploading them to S3. When I upload my updated sitemap.xml and rss.xml files though, S3 nukes my custom Content-Type settings.
Is there a way to get it to associate these settings with the name of the file as opposed to the instance of the file?

Specify content-type for documents uploaded in Magnolia

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?

Setting mime-type on S3 object

Is there a way to have S3 automatically set a mime-type depending on extension? I don't want my uploads to force download if I don't specify a mime-type but rather have the browser decide.
S3 won't do this for you, but most tools and APIs will allow you to specify the MIME type when uploading. Depending on the context you're working with, you should be able to do this relatively easily yourself, and some tools (e.g. Bucket Explorer) will allow you to do mass-assignment of MIME types based on file extension.