app/models/concen/grid_file.rb in concen-0.2.8 vs app/models/concen/grid_file.rb in concen-0.2.9
- old
+ new
@@ -48,11 +48,11 @@
# There is no update.
grid.delete(self.grid_id) if self.grid_id
original_filename = filename.dup
file_extension = File.extname(original_filename).downcase
- content_type = MIME::Types.type_for(original_filename).first.to_s
+ content_type = content_type_for original_filename
# Pre generate ObjectId for the new GridFS file.
grid_id = BSON::ObjectId.new
filename = File.basename(original_filename, file_extension).downcase.parameterize.gsub("_", "-")
@@ -61,9 +61,19 @@
if grid.put(content, :_id => grid_id, :filename => filename, :content_type => content_type, :safe => true)
self.update_attributes(:grid_id => grid_id, :filename => filename, :original_filename => original_filename)
else
return false
end
+ end
+
+ def content_type_for(filename)
+ content_type = MIME::Types.type_for(filename).first.to_s
+
+ # Special cases when mime-types fails to recognize
+ content_type = "video/mp4" if filename.include?(".mp4")
+ content_type = "video/x-m4v" if filename.include?(".m4v")
+
+ return content_type
end
protected
def destroy_gridfs