rails upyun上传图片的例子

访问量: 791

核心是使用了rubygem:  upyun,  另外,记得要绑定好 二级域名(image.happysoft.cc)

  require 'upyun'
  def create
    @upload = Upload.new(upload_params)
    @upload.save

    bucket = 'generic'
    operator = 'operator_id'
    password = 'your password'
    upload_file = params[:file]
    upyun = Upyun::Rest.new(bucket, operator, password)
    remote_file = "/image/#{@upload.id}/#{upload_file.original_filename}"
    response = upyun.put remote_file, upload_file.read
    render :json => {
      :response => response,
      :url => "http://image.happysoft.cc#{remote_file}"
    }   
  end 

订阅/RSS Feed

Subscribe

分类/category