Rails Active Storage - Preview all the Audio/Video files in the browser - ruby-on-rails-5

I am using Rails(5.2) Active Storage for saving attachments directly in S3.
After the attachment is saved in the model, the image and pdf files are previewed in the browser directly by clicking on the file url, which is the default behaviour due to active_storage.content_types_allowed_inline configuration.
I need some extra files to be previewed through browser like Audio/Video files, I have added the file content types in the configuration like below,
config.active_storage.content_types_allowed_inline += %w[audio/flac audio/x-flac audio/mpeg audio/mp3
audio/mp4 audio/ogg audio/wave audio/wav audio/x-wav audio/x-pn-wav audio/webm
video/mpeg video/mp4 video/ogg video/quicktime video/webm
video/x-msvideo video/x-flv video/h264 application/vnd.rn-realmedia application/x-shockwave-flash
video/x-ms-wmv audio/x-aiff audio/midi application/ogg audio/x-ms-wma application/vnd.ms-wpl
video/x-matroska video/dvd video/x-ms-vob]
The files like mp3, mp4 are previewing in the browser.
But files like avi, flv, h264, mkv, rm, swf, wmv, aif, midi, mpa, wma are downloading instead of previewing but I have added these file content types in the content_types_allowed_inline configuration also.
How to preview all the audio/video files in the browser? Does anybody have any idea in this?

Related

Apache Server - Content-Type HTTP Header

Hi I am having an issue where the client side is unable to connect/play video content from a .mp4 asset file located on an Apache Server.
I am suspecting the issue has to do with the Content-Type parameter in the HTTP Headers.
How can I modify this Content-Type parameter to see if this is the issue?
I'd like to try video/mp4, audio/mp4, audio/m4a, audio/aac, etc.
To fix this issue on Apache you need to add the following content to the ‘.htaccess‘ file which is found in your document root (public_html or htdocs).
just paste this to your .htaccess (required mime types)
AddType video/mp4 mp4 m4v
AddType audio/mp4 m4a
You can also add these mime types directly in the Apache configuration file ‘mime.types’
/etc/httpd/conf/mime.types
add required mime.types.
video/mp4 mp4 m4v
audio/mp4 m4a
then restart apache.

Apache ignoring mime-type

I have a page that is using JWPlayer to serve a video in a variety of format choices (mp4, m4v, ogv, webm). However, when accessing the page from Firefox (23.0.1) or with PHP curl, Apache is returning a header indicating the content-type as text/plain. Firefox (and newer IE versions, unless in compatibility mode) will not play the video. I have tried adding the mime types in mime.types, httpd.conf, and in an .htaccess file in the directory.
mime.types
video/mp4 mp4 m4v
video/ogg ogv
video/webm webm
httpd.conf
AddType video/mp4 mp4 m4v
AddType video/ogg ogv
AddType video/webm webm
.htaccess
AddType video/mp4 mp4 m4v
AddType video/ogg ogv
AddType video/webm webm
I have tried with and without the dot in front of the extensions (which as I understand should work either way). I have restarted Apache. I have verified that I am editing the right configuration files. Still Apache continues to return the text/plain type. Where have I gone wrong?
UPDATE: Tried FilesMatch and ForceType directive as suggested by rekire in httpd.conf, virtualhost, and .htaccess. Tried renaming files and changing links to match in case of middleman caching. Going straight to the URL downloads the video and allows to play it in desktop player normally.
In the official documentation for AddType of mod_mime are the file extensions listed with a leading dot so try this:
AddType video/mp4 .mp4 .m4v
AddType video/ogg .ogv
AddType video/webm .webm
Or try ForceType together with FilesMatch:
<FilesMatch "\.(mp4|m4v)$">
ForceType video/mp4
</FilesMatch>
Answering my own question, over 2 years later. It turned out to be an issue that was not determinable from the information I gave in the question, and a relatively simple problem. There was an .htaccess file that was routing ALL requests - existing resource files or not - to a PHP file, which was then handling all file requests itself, including returning a MIME type, effectively bypassing all of the handling I was attempting to do in Apache.

Firefox error with Video JS

I am getting an error in Firefox (ver 22/23) that says:
Specified "type" attribute of "video/mp4" is not supported. Load of media resource xxxxx failed.
Is this repairable?
It's all about MIME types. When you specify type attribute on your video source - you also need to make sure your server understands what that types of files actually mean.
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
Add these lines to your server's .htaccess file and you'll be up'n'running.
For any additional information related to video conversion/playback - check out this article

Apache download files with specific extension

I have download directory on apache webserver. Files in this directory have specific extensions. For example *.yyy and *.zzz. But all these files are renamed .zip or .tar.gz
I've tested in different brawsers and havn't got any problems.
But some users tell that they get source of packages, not download.
I've created.htaccess
AddType application/zip .zzz
AddType application/x-gzip .yyy
But when I try to download aaa.yyy in MS Internet Explorer it try to save not aaa.yyy but aaa.gz
How to force browsers download files and not to change extensions?
<FilesMatch "\.(zzz|yyy)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Force type tell browsers that you dont know file type. So they are not going to do any thing stupid. Second line will tell them to download this file.

how to change mime types in MAMP

I'm developing a website that has a HTML5 video. It looks like when ogg files are served with other mime types than video/ogg firefox flips. I've updated the mime.types file inside the mamp/apache/config folder and have restarted the MAMP server multiple times, but ogg files are still served with plain/text context-type.
Can someone point out what I need to do?
UPDATE
The only time I'm able to change the mime type is if I change the DefaultType text/plain to DefaultType video/ogg which is stupid.
The mime.types file is in Applications/MAMP/conf/apache
There you can alter your mime types.
Reset server after changing the file for it to take effect.
Do you have mod_mime_magic installed and enabled? Is your mime magic working correctly? When you do file -m on one of your OGG files, does it say it is a plain text file? Are the file extensions correct?
Adding mime-type is the same for all, it's just you need to understand how the types will be applied and what's the mime-type point is. In this answer I'll how I tried to add WebAssembly mime-type application/wasm in MAMP.
Here it goes:
I recently tried WebAssembly in MAMP and configured out the below mime-type that works for me.
First, we need to navigate the folder of MAMP in MacOS's Applications/MAMP/conf/apache, And then open the file mime.types in any editor.
After opening the file, add the following line anywhere in the mime.types file:
application/wasm wasm
Here is the example wasm mime type in my mime.types file:
#application/wasm
application/wasm wasm
In MAMP Pro these days you can add <VirtualHost> parameters using the gui. Here's a screenshot showing how I add MIME types for .mjs and .wasm as:
AddType application/javascript .mjs
AddType application/wasm wasm
screenshot
Don't forget to restart the server after adding.