把本地已经存在的图片上传到up云
访问量: 2628
把下面代码COPY到某个RB文件中并执行。
前提是你有了 bucket, operator, operator password..
# copy_all_files_to_upyun.rb
require 'upyun'
upyun = Upyun::Rest.new('your_bucket', 'operator_name', 'password')
# 本地路径: ./folder/1/2/3.jpg, 那么,上传到 远程后,应该是: /1/2/3.jpg, happyteam.b0.upaiyun.com/1/2/3.jpg
# 执行这个脚本的要求是:
# 1. cd 到 目标文件夹的同级目录,例如: /opt/app/yuehouse_web/public
# 2. 目标文件夹(例如: files ). 直接:
root ='/opt/app/yuehouse/shared/public'
folder = '/uploads'
files_and_folders = `find #{root + folder}`
files_and_folders.split("\n").select{ |entity|
entity.include?(".")
}.each { |file|
remote_file_path = file.sub(root, '')
puts "=remote_file_path: #{remote_file_path.inspect}"
puts "= local file: #{file.inspect}"
puts upyun.put(remote_file_path, File.new(file))
}