Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created October 8, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoward/56e39e60f00289625f84 to your computer and use it in GitHub Desktop.
Save ahoward/56e39e60f00289625f84 to your computer and use it in GitHub Desktop.
//
s3Uploader.content_type_for = function(file_input, file_name, content_type){
content_type = content_type || 'application/octet-stream';
try{
content_type = jQuery(file_input).prop('files')[0]['type']
} catch(e) {};
if(!content_type){
var parts = file_name.split('.');
var base = parts.shift();
var ext = parts.pop().toLowerCase().trim();
switch(ext){
case 'jpg':
case 'jpeg':
content_type = 'image/jpeg';
break;
case 'png':
content_type = 'image/png';
break;
case 'gif':
content_type = 'image/gif';
break;
case 'tiff':
case 'tif':
content_type = 'image/tiff';
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment