把本地的图片文件同步到upyun (还是记录一下吧。)
访问量: 2307
很简单。就是一句 upyun.put
# -*- encoding : utf-8 -*- require 'upyun' upyun = Upyun::Rest.new('yuehouse', 'zhang', 'zhang123') # 本地路径: ./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 ='/Users/zhang/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 "=remote_file_path: #{remote_file_path.inspect}" puts "= local file: #{file.inspect}" puts upyun.put(remote_file_path, File.new(file)) }