Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

.htaccess - Changing video content type (mime type) in CDN in drupal 7

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...