Assuming the file doesn't exist or you want to overwrite its current content, you just need to open the file with mode wb
(w
for write, b
for binary — the b
may not be strictly necessary on all systems). If you're trying to append to a file, use ab
instead. See this page for more information on modes.
File.open(filename, 'wb') do |f|
f.write blob
end