Changing video content type (mime type) in CDN in drupal 7
Asked Answered
D

2

2

I am using media module to save media in CDN. To play videos, we are using jwplayer in Drupal 7. Jwplayer throws error in IE, If video is not of content type [mime type] *video/mp4*. I have changed the existing CDN videos mime type from application/octet-stream to video/mp4.

Now whatever mp4 videos are being uploaded/saved to cdn should only be of video/mp4 mime type but when I upload mp4 videos in media module it is saved in CDN with mime type application/octet-stream, How do I change the uploaded mime type [content type] to video/mp4.

CDN module code 

function CDNtransfer_content($source,$destination)  {

        $s3=_CDN_transfer_load();

        $up_bucket="cdn.example.com";

        $uploadOk=null;

        $expires=date('D, d M Y H:i:s O', strtotime('+10 year'));

        $headers=array('Content-Type' => 'video/mp4', 'Expires' => $expires);

        if($destination)
        {
                        $up_state=$s3->putObject($up_bucket, $destination, $source, 'true', $headers);

                        if($s3->objectExists($up_bucket, $destination)) {
                            $uploadOk =1;
                        }
                        else {
                            $uploadOk ="Error: File Not Uploaded Correctly. Please try again.";
                        }
        }
        return $uploadOk;
}

Even setting the above header does not seem to work !!! not sure why ??

We are using s3 php sdk 2 aws stand alone class with our custom module in drupal.

How do I change mime type[content type] to video/mp4 in media module, Drupal 7, when mp4 video are being uploaded.

Disinclined answered 18/2, 2014 at 8:10 Comment(0)
B
1

A MIME-TYPE is a server side setting. You can ask your hosting provider to add the MP4 MIME-TYPE for you.

Or, you can add a .htaccess file to the directory where you uploads are stored.

A sample .htaccess file that adds the MP4 MIME-TYPE is:

<IfModule mod_rewrite.c>
  AddType video/mp4 .mp4
</IfModule>

If you are not able to add the MIME TYPE properly, one work around you can use is to force the JW Player to run as Flash, which is less strict about MIME-TYPEs, by adding this line, to your player's embed code:

primary: 'flash',

Let me know if this helps!

Beleaguer answered 18/2, 2014 at 14:46 Comment(9)
I am checking this with my team.... I found somthing similiar here https://mcmap.net/q/139168/-set-content-type-of-media-files-stored-on-blob don't we have any option like this ??Disinclined
Are you storing the files on blob?Beleaguer
I changed in .htaccess file but does not seems to work for the CDN.I Found these two links which had some what simliar problem but no solution --> #9091208 ..... forums.aws.amazon.com/thread.jspa?messageID=420907&#420907Disinclined
Also your second solution only works with browser if you need to use in tablet it will again create problem ... @ethan : Is there any other work around for this ... or solution ... I am sure it is known issue ... how other customer are using jwplayer with CDN for IE browserDisinclined
Yes, this is why you need to set the MIME TYPE to fully fix this issue. Setting flash to primary just masks the issue but doesn't get to the real issue at hand.Beleaguer
I did try that but it is not changing ... is there any example code for this ... I tried changing the header value for the file .... github.com/tpyo/amazon-s3-php-class ......as given here S3::putObject($string, $bucketName, $uploadName, S3::ACL_PUBLIC_READ, array(), array('Content-Type' => 'text/plain')).....but it is not working .... :(Disinclined
Can I see where you are running this?Beleaguer
found the problem .... it was old s3 class file not same as github.com/tpyo/amazon-s3-php-class and did not had the 'mp4'=>'video/mp4' element in the mime_type array.Disinclined
Here is a blog post with a comprehensive list of extension to mimetype mappings. ppolyzos.com/2015/10/27/…Venatic
D
1

Found the Answer :

1) As Ethan said "A MIME-TYPE is a server side setting. You can ask your hosting provider to add the MP4 MIME-TYPE for you.

Or, you can add a .htaccess file to the directory where you uploads are stored".

A sample .htaccess file that adds the MP4 MIME-TYPE is:

<IfModule mod_rewrite.c>
  AddType video/mp4 .mp4
</IfModule>"

Source : Need to Change Video Content Type to video/mp4 so it plays in IE

But this did not work for me for some reason

2) I did the change in my core class file which i was using in drupal module for CDN upload I had made a change in my class.s3.php file -> in mime_type[] array and also, cross checked with putObject() function.

**

Setting of mime type is always done in coding side and not in AWS S3 bucket, We need to use AWS PHP Class file or sdk to do the manipulation in mime type or make the necessary changes in core class file (eg. class.s3.php )

** For details check here find-mime-type-of-file-or-url-using-php-for-all-file-format

Second Answer has worked for me :)

Disinclined answered 28/2, 2014 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.