Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
Created March 3, 2015 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saboyutaka/7ad2dc1e4e5a9c361d04 to your computer and use it in GitHub Desktop.
Save saboyutaka/7ad2dc1e4e5a9c361d04 to your computer and use it in GitHub Desktop.
画像保存スクリプト
def save_image(url)
# ready filepath
fileName = File.basename(url)
dirName = "/var/tmp/hoge/"
filePath = dirName + fileName
# create folder if not exist
FileUtils.mkdir_p(dirName) unless FileTest.exist?(dirName)
# write image adata
open(filePath, 'wb') do |output|
open(url) do |data|
output.write(data.read)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment