一个自动上传图片到又拍云的ruby脚本

require 'upyun'

 

upyun = Upyun::Rest.new('bucket', 'operator', 'password')

 

# 本地路径:  ./folder/1/2/3.jpg, 那么,上传到 远程后,应该是:  <host>/1/2/3.jpg, happyteam.b0.upaiyun.com/1/2/3.jpg

 

 

# 执行这个脚本的要求是:

# 1. cd 到 目标文件夹的同级目录,例如:  /opt/app/yuehouse_web/public

# 2. 目标文件夹(例如: files ). 直接:

root ='/Users/zhangyu/Pictures'

folder = '/files'

files_and_folders = `find #{root + folder}`

 

files_and_folders.split("\n").select{ |entity|

  entity.include?(".")

}.each { |file|

  remote_file_path = file.sub(root, ''

  puts upyun.put(remote_file_path, File.new(file))

}

 

posted on 2015-08-21 17:15  技生瑜合声靓  阅读(213)  评论(0编辑  收藏  举报

导航