Changing video content type (mime type) in CDN in drupal 7

二次信任 提交于 2019-11-28 09:32:23

问题


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.


回答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!




回答2:


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 :)



来源:https://stackoverflow.com/questions/21847663/changing-video-content-type-mime-type-in-cdn-in-drupal-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!