1

How do I set the mime-type of files being served from the drupal private directory. I have a webm file in the private directory, and the I've added the <video> tag to the page using a tpl file.

I've tried adding

AddType video/webm .webm

to .htaccess. I've also tried installing the module "File Mime" to try to set the right mime type. I've tried adding

function mymodule_file_download($uri){
    return array('Content-type: '.'video/webm');
}

to my .module file. Nothing seems to work. Any help would be appreciated.

3

Editing includes/files.mimetypes.inc is a core hack, which you should strive to avoid.

Instead, use hook_file_mimetype_mapping_alter():

function mymodule_file_mimetype_mapping_alter(&$mapping) {
  // Add new MIME type 'video/webm'.
  $mapping['mimetypes']['webm'] = 'video/webm';
  // Add new extension '.webm' and map it to the 'video/webm' MIME type.
  $mapping['extensions']['webm'] = 'webm';
}
-1

Figured this out myself: I had to add the webm mimetype in the appropriate places in the includes/files.mimetypes.inc file to get drupal to serve private files with the correct mimetype.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.