mongoid / mongoid-grid_fs

A pure Mongoid/Moped implementation of the MongoDB GridFS specification.
Other
83 stars 50 forks source link

Is there anyway to upload file to GridFS from a blob? #24

Closed abhas closed 11 years ago

abhas commented 11 years ago

I'm using the rmagick gem to split a PDF into images and store the resulting images into GridFS. However, this gem requires me to pass a file path to store a file to GridFS. Is there a way I could pass a blob and store it as a file?

In the earlier mongoid_grid gem, I could use a set_file method to set the contents of a file that I was uploading. I wish I could do the same thing here without having to first write the file to a temporary file.

Thanks a lot!

rmm5t commented 11 years ago

@abhas Because the GridFS specification expects a file path (just like you need to have a file path to store a file on your local filesystem or S3), a path is eventually necessary.

However, this gem can store anything that's deemed "readable." If you give put just a file path, it will try to open it for reading. If you give it something that responds to read, it will just do that. put also takes :filename option if you want to give it an explicit filename. Alternatively, you can use []= to assign a readable object to a filename.