1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| class UploadsController < ApplicationController before_action :set_upload, only: [:show, :edit, :update, :destroy] def new @upload = Upload.new respond_with(@upload) end
require 'upyun' def create @upload = Upload.new(upload_params) @upload.save
bucket = 'upyun空间的名称' operator = '操作员名称' 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:/xxxx.b0.upaiyun.com/#{remote_file}" } end end
|