Created
March 3, 2015 00:53
-
-
Save saboyutaka/7ad2dc1e4e5a9c361d04 to your computer and use it in GitHub Desktop.
画像保存スクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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