dimanche 26 juillet 2015

Stop file write if file size exceeds 500KB ruby on rails

How can I stop file writing ( upload form remote url ) when file size exceeds 500KB ?

I am using following code to upload a remote file

require 'open-uri'
open('temp/demo.doc', 'wb') do |file|
  file << open('http://ift.tt/1LJxj3W').read
end

this code is working properly and I am able to get files in temp folder. Now I want if filesize exceeds 500KB then it should stop writing file. In other words I want only 500KB of file if it is more than 500KB

Aucun commentaire:

Enregistrer un commentaire