云服务 请教 UPYUN 设置问题

kevinhua · 2012年04月03日 · 最后由 kevinhua 回复于 2012年12月05日 · 3272 次阅读

根据 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)



是系统自带的 imagemagick 有点问题,可使用 graphicsmagick 替代:

安装 graphicsmagick

sudo apt-get install graphicsmagick

指定 gm 作为 MiniMagick 的 processor:

在 app/uploaders/base_uploader.rb 中,在include CarrierWave::MiniMagick下面一行添加:

# To force MiniMagick to us gm as processor
MiniMagick.processor = :gm

Another solution:

> wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
> tar -xzvf ImageMagick.tar.gz
> ./configure --prefix=/usr/local --with-x=no --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --disable-openmp
> make
> sudo make install
> sudo /sbin/ldconfig /usr/local
> sudo ln -f /usr/local/bin/Magick-config /usr/bin/Magick-config
需要 登录 后方可回复, 如果你还没有账号请 注册新账号