lib/mongo_grid.rb in mongo_grid-0.1.8 vs lib/mongo_grid.rb in mongo_grid-0.1.9
- old
+ new
@@ -24,13 +24,12 @@
content_type=upload.content_type
if content_type.include?("image")
::Zbox::Qm.resize(upload.tempfile.path,opts)
end
data = File.open(upload.tempfile.path)
- gfile = ::Mongo::Grid::File.new(data,filename: filename, content_type: content_type)
+ length=File.size(upload.tempfile.path)
+ gfile = ::Mongo::Grid::File.new(data,filename: filename, metadata: {content_type: content_type,length: length})
gid = grid.insert_one(gfile)
- grid_data=grid.find_one(_id: gid)
- length=grid_data.chunk_size
file_size =
case length
when 0..(1024**2)
(length.to_f/1024.to_f).round(1).to_s+"K"
when (1024**2)...(1024**3)