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))
}
时间: 2024-11-11 08:12:31