根据 carrierwave-upyun 说明文件,已经添加:
###config/config.yml
upload_url: "http://hujoy.b0.upaiyun.com"
upyun_username: "username"
upyun_password: "password"
upyun_bucket: "hujoy"
###config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :upyun
config.upyun_username = Setting.upyun_username
config.upyun_password = Setting.upyun_password
config.upyun_bucket = Setting.upyun_bucket
config.upyun_bucket_domain = Setting.upload_url.gsub("http://","")
end
###app/uploaders/base
# encoding: utf-8
require 'carrierwave/processing/mini_magick'
class BaseUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :upyun
... ...
end
但上传头像时,会显示“图像处理错误”,在贴子中上传图片时,上传不会成功,也不会插入链接。
###看了一下 development.log,提示错误如下:
Started POST "/photos?tiny=1" for 127.0.0.1 at 2012-04-04 00:00:26 +0800
Processing by PhotosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "image1"=>#<ActionDispatch::Http::UploadedFile:0x00000004e059d0 @original_filename="Revolutionary.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"image1\"; filename=\"Revolutionary.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20120404-9886-55qlzc>>, "commit"=>"上传并插入代码", "tiny"=>"1"}
MONGODB hujoy_db_development_apr1['users'].find({:_id=>1}).limit(-1).sort([[:_id, :asc]])
/photos/create save faield: Image 处理错误
Redirected to http://hujoy.com:3000/photos/tiny_new
Completed 302 Found in 46ms
Started GET "/photos/tiny_new" for 127.0.0.1 at 2012-04-03 15:49:28 +0800
Processing by PhotosController#tiny_new as HTML
MONGODB hujoy_db_development_apr1['users'].find({:_id=>1}).limit(-1).sort([[:_id, :asc]])
Rendered photos/tiny_new.html.erb within layouts/window (1.0ms)
Completed 200 OK in 10ms (Views: 3.3ms | Mongo: 0.3ms | Solr: 0.0ms)