0

I have a GridFS file object

Mongoid::GridFs::Fs::File _id: 53a277dc700ca7ac146f5797, length: 2237337, chunkSize: 261120, uploadDate: 2014-06-19 05:40:44 UTC, md5: "390968a8ef198f8537495468366f67b9", filename: "720p_5.MP4", contentType: "binary/octet-stream", aliases: nil, metadata: nil

Now I need a Tempfile(or File will do) instance from that

File:/tmp/fileupload20140620-4601-19via7k

Since the file that I process is a video file i need to further process it with the ffmpeg to get different versions of the video file

normally I could get a tmp file but the tempfile size seems to be quite low for a video file and the ffmpeg also gives error, may be the temp file created is not correct. I have no idea what did i do wrong.

zishe
  • 10,665
  • 12
  • 64
  • 103
Ojash
  • 1,234
  • 8
  • 20

1 Answers1

0

This seems to do the trick for me, I get the necessary object (i.e. File object) in the tempfile that i can convert using ffmpeg.

<!--language: ruby-->
a = Mongoid::GridFs.get(file_id.to_s)  
extn = File.extname  a.filename  
name = File.basename a.filename, extn  
tempfile = Tempfile.new([name,extn])  
tempfile.binmode  
tempfile.write(a.data)
Ojash
  • 1,234
  • 8
  • 20