Qiniu Storage support for CarrierWave
Home Page: https://huobazi.github.com/carrierwave-qiniu/
License: MIT License
已经解决。。不好意思
.../config/initializers/carrierwave.rb:8:in `block in <top (required)>': undefined method `qiniu_bucket_private=' for CarrierWave::Uploader::Base:Class (NoMethodError)
from /Users/bishop/.rvm/gems/ruby-2.1.4/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
from /Users/bishop/.rvm/gems/ruby-2.1.4/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
from /Users/bishop/project/medical/ourdrs/config/initializers/carrierwave.rb:2:in `<top (required)>'
from /Users/bishop/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
配置我照抄:
config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :qiniu
config.qiniu_access_key = "your qiniu access_key"
config.qiniu_secret_key = 'your qiniu secret_key'
config.qiniu_bucket = "carrierwave-qiniu-example"
config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
config.qiniu_bucket_private= true #default is false
config.qiniu_block_size = 4*1024*1024
config.qiniu_protocol = "http"
end
Gemfile:
gem 'carrierwave'
gem 'carrierwave-qiniu'
gem 'qiniu-rs'
bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'carrierwave-qiniu'. (Bundler::GemRequireError)
我使用了 carrierwave-qiniu 来做上传的一些工作,最近经常发现会有上传完毕的图片在过了几天之后莫名地被删除了。
我请七牛那边大概查了一下,发出的请求头里有 carrierwave 的字样
问题是,我们的项目根本没有删除图片的功能,也从来没用到七牛的删除接口
所以想请问一下,carrierwave-qiniu 在那些情况下,会向七牛的服务器发送删除资源的请求?
算法是从qiniu ruby-sdk上参考的。。因为项目需要文件url过时。。找了半天。。
require "hmac-sha1"
def authorize_url(url = self.url, auth_time = 1.hour)
auth_url = "#{url}?e=#{(Time.now + auth_time).to_i}"
sign = HMAC::SHA1.new(self.qiniu_secret_key).update(auth_url).digest
token = Base64.encode64(sign).strip.gsub('+', '-').gsub('/','_').gsub(/\r?\n/, '')
"#{auth_url}&token=#{self.qiniu_access_key}:#{token}"
end
bundle install 完成之后,rails s遇到以下报错:
/Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'carrierwave-qiniu'. (Bundler::GemRequireError)
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /Users/foo/Dev/blademaster/config/application.rb:7:in `<top (required)>'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:78:in `require' from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:75:in `server' from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/foo/.rvm/gems/ruby-2.2.2/gems/railties-4.2.5.2/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我的Gemfile如下:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem 'mysql2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'omniauth'
gem 'devise'
gem 'devise_token_auth'
gem 'omniauth-github'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'rack-cors', :require => 'rack/cors'
gem 'activeadmin', '~> 1.0.0.pre4'
gem 'will_paginate', '~> 3.1.0'
gem 'alipay', '~> 0.12.0'
gem 'unicorn'
gem 'yui-compressor'
gem 'sidekiq'
gem 'carrierwave'
gem 'carrierwave-qiniu'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'better_errors', '~> 2.1.1'
gem 'binding_of_caller'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
gem "spring", group: :development
Rails新手表示不清楚问题出现的原因。
My problem,
There was an error while trying to load the gem 'carrierwave-qiniu'. (Bundler::GemRequireError)
Gem Load Error is: You dot't have the 'qiniu-rs' gem installed
But qiniu-rs was deprecated.
TypeError - class or module required for rescue clause:
qiniu-rs (1.1.0) lib/qiniu/rs/auth.rb:64:in rescue in request' qiniu-rs (1.1.0) lib/qiniu/rs/auth.rb:62:in
request'
qiniu-rs (1.1.0) lib/qiniu/rs/rs.rb:27:in publish' qiniu-rs (1.1.0) lib/qiniu/rs.rb:95:in
publish'
carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:88:in setup_publish_bucket_and_domain' carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:75:in
init'
carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:27:in initialize' carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:142:in
qiniu_connection'
carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:112:in store' carrierwave-qiniu (0.0.7.1) lib/carrierwave/storage/qiniu.rb:150:in
store!'
carrierwave (0.11.2) lib/carrierwave/uploader/store.rb:59:in block in store!' carrierwave (0.11.2) lib/carrierwave/uploader/callbacks.rb:17:in
with_callbacks'
carrierwave (0.11.2) lib/carrierwave/uploader/store.rb:58:in store!' carrierwave (0.11.2) lib/carrierwave/mount.rb:375:in
store!'
carrierwave (0.11.2) lib/carrierwave/mount.rb:207:in store_file!' activesupport (4.2.6) lib/active_support/callbacks.rb:432:in
block in make_lambda'
activesupport (4.2.6) lib/active_support/callbacks.rb:228:in block in halting_and_conditional' activesupport (4.2.6) lib/active_support/callbacks.rb:506:in
block in call'
activesupport (4.2.6) lib/active_support/callbacks.rb:506:in call' activesupport (4.2.6) lib/active_support/callbacks.rb:92:in
run_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in _run_save_callbacks' activerecord (4.2.6) lib/active_record/callbacks.rb:302:in
create_or_update'
activerecord (4.2.6) lib/active_record/persistence.rb:120:in save' activerecord (4.2.6) lib/active_record/validations.rb:37:in
save'
activerecord (4.2.6) lib/active_record/attribute_methods/dirty.rb:21:in save' activerecord (4.2.6) lib/active_record/transactions.rb:286:in
block (2 levels) in save'
activerecord (4.2.6) lib/active_record/transactions.rb:351:in block in with_transaction_returning_status' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
block in transaction'
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/transaction.rb:184:in within_new_transaction' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction'
activerecord (4.2.6) lib/active_record/transactions.rb:220:in transaction' activerecord (4.2.6) lib/active_record/transactions.rb:348:in
with_transaction_returning_status'
activerecord (4.2.6) lib/active_record/transactions.rb:286:in block in save' activerecord (4.2.6) lib/active_record/transactions.rb:301:in
rollback_active_record_state!'
activerecord (4.2.6) lib/active_record/transactions.rb:285:in save' app/controllers/admin/videos_controller.rb:11:in
block in create'
actionpack (4.2.6) lib/action_controller/metal/mime_responds.rb:212:in respond_to' app/controllers/admin/videos_controller.rb:10:in
create'
actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (4.2.6) lib/abstract_controller/base.rb:198:in
process_action'
actionpack (4.2.6) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.2.6) lib/abstract_controller/callbacks.rb:20:in
block in process_action'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in call' activesupport (4.2.6) lib/active_support/callbacks.rb:555:in
block (2 levels) in compile'
activesupport (4.2.6) lib/active_support/callbacks.rb:505:in call' activesupport (4.2.6) lib/active_support/callbacks.rb:92:in
run_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in _run_process_action_callbacks' activesupport (4.2.6) lib/active_support/callbacks.rb:81:in
run_callbacks'
actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in
process_action'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (4.2.6) lib/active_support/notifications.rb:164:in
block in instrument'
activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.6) lib/active_support/notifications.rb:164:in
instrument'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in
process_action'
activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.2.6) lib/abstract_controller/base.rb:137:in
process'
actionview (4.2.6) lib/action_view/rendering.rb:30:in process' actionpack (4.2.6) lib/action_controller/metal.rb:196:in
dispatch'
actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.6) lib/action_controller/metal.rb:237:in
block in action'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in dispatch' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in
serve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in block in serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in
serve'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in call' rack-pjax (0.8.0) lib/rack/pjax.rb:12:in
call'
rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4) lib/rack/conditionalget.rb:38:in
call'
rack (1.6.4) lib/rack/head.rb:13:in call' remotipart (1.2.1) lib/remotipart/middleware.rb:27:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in call' actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in
call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context' rack (1.6.4) lib/rack/session/abstract/id.rb:220:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in call' activerecord (4.2.6) lib/active_record/query_cache.rb:36:in
call'
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in call' activerecord (4.2.6) lib/active_record/migration.rb:377:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (4.2.6) lib/active_support/callbacks.rb:88:in
run_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in _run_call_callbacks' activesupport (4.2.6) lib/active_support/callbacks.rb:81:in
run_callbacks'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in call' better_errors (2.1.1) lib/better_errors/middleware.rb:84:in
protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in better_errors_call' better_errors (2.1.1) lib/better_errors/middleware.rb:57:in
call'
rollbar (2.12.0) lib/rollbar/middleware/rails/rollbar.rb:24:in block in call' rollbar (2.12.0) lib/rollbar.rb:735:in
scoped'
rollbar (2.12.0) lib/rollbar/middleware/rails/rollbar.rb:22:in call' actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in
call'
rollbar (2.12.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in call_with_rollbar' web-console (2.3.0) lib/web_console/middleware.rb:28:in
block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in call' actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in
call'
railties (4.2.6) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.6) lib/rails/rack/logger.rb:20:in
block in call'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in
tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.6) lib/rails/rack/logger.rb:20:in
call'
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.6.4) lib/rack/methodoverride.rb:22:in
call'
rack (1.6.4) lib/rack/runtime.rb:18:in call' activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in
call'
rack (1.6.4) lib/rack/lock.rb:17:in call' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in
call'
rack (1.6.4) lib/rack/sendfile.rb:113:in call' rack-cors (0.4.0) lib/rack/cors.rb:80:in
call'
railties (4.2.6) lib/rails/engine.rb:518:in call' railties (4.2.6) lib/rails/application.rb:165:in
call'
rack (1.6.4) lib/rack/lock.rb:17:in call' rack (1.6.4) lib/rack/content_length.rb:15:in
call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in service' /home/quinlee/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:138:in
service'
/home/quinlee/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in run' /home/quinlee/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in
block in start_thread'
图片上传到的qiniu
执行 ProductImage.find(61585).picture_url.recreate_versions! 返回
D, [2016-10-14T14:34:12.671465 #14169] DEBUG -- : [httplog] Connecting: uat.image.kjds.com:80
D, [2016-10-14T14:34:12.798838 #14169] DEBUG -- : [httplog] Sending: GET http://uat.image.kjds.com:80/uploads/product_image/picture_url/61585/wer.png
D, [2016-10-14T14:34:14.134007 #14169] DEBUG -- : [httplog] Status: 200
D, [2016-10-14T14:34:14.134253 #14169] DEBUG -- : [httplog] Benchmark: 1.3349422269966453 seconds
D, [2016-10-14T14:34:14.134425 #14169] DEBUG -- : [httplog] Response: (not showing binary data)
W, [2016-10-14T14:34:14.135568 #14169] WARN -- : incompatible character encodings: UTF-8 and ASCII-8BIT => Qiniu::HTTP.get('http://uat.image.kjds.com/uploads/product_image/picture_url/61585/wer.png')
TypeError: no implicit conversion of nil into String
from uby-2.3.0@camp/gems/carrierwave-0.10.0/lib/carrierwave/uploader/cache.rb:83:in `initialize'
这两个找不到
Hi there,
I failed to install carrierwave-qiniu as the following problem.
As it indicated, carrierwave-qiniu requires qiniu (~> 6.4.2), but I had qiniu (= 6.5.1) installed already, it shall not caused any problem.
Bundler could not find compatible versions for gem "qiniu":
In snapshot (Gemfile.lock):
qiniu (= 6.5.1)
In Gemfile:
carrierwave-qiniu (>= 0) ruby depends on
qiniu (~> 6.4.2) ruby
qiniu (>= 0) ruby
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
Let me know if you have any idea.
升级到任何高于 0.0.7.1 版本都会出依赖错误:
Bundler could not find compatible versions for gem "rest-client":
In snapshot (Gemfile.lock):
rest-client (= 1.8.0)
In Gemfile:
carrierwave-qiniu (= 0.2.4) was resolved to 0.2.4, which depends on
qiniu (> 6.5.1) was resolved to 6.5.1, which depends on> 1.7.3)
rest-client (
目前有一个需求,需要上传大的视频文件到七牛,是否支持呢
我想问下,在七牛的ruby-sdk当中可以在 https://github.com/qiniu/ruby-sdk/blob/master/lib/qiniu/config.rb 修改up_host,在carrierwave当中应该怎么修改这个host呢?
大致流程是这样,用户在第一次上传了一头像图片后,觉得不合适,又重新选择了一张想进行覆盖,结果会报错:
Uploading Failed. HTTP Status Code: 614. HTTP response body: :error => file exists.
根据七牛的api,应该是在上传策略里面将scope的值赋值为:的形式,发现在这个gem里面没法进行自定义上传/下载/管理 策略。或者说我没有找到正确的方法?
没人发现 README 里的 config/initializes/carrierwave.rb 单词拼错了吗?initializes -> initializers
source 'https://gems.ruby-china.org'
gemfile中直接添加gem 'carrierwave-qiniu',会安装其他源的carrierwave-qiniu
gem 'carrierwave-qiniu', git: 'https://github.com/huobazi/carrierwave-qiniu.git' 这样才能解决
我们项目上依赖了qiniu gem(6.2.1), 而carrierwave-qiniu使用的是qiniu-rs(3.4.9),不知道你们准备更新么?
qiniu, qiniu-rs同时使用,不知道是否会冲突?
RT
仍然有一个commit的author信息不正确,我无法push。
视频上传的时候要加一个进度条,但是这个进度条在数据存到本地数据库是就走到百分百了,实际上后台还在向七牛上传,并没有完成,这个要怎么解决会好一些?
hi 你好
看了一遍代码,好像目前不支持在设置上传策略的时候写入这两个回调参数。请问有办法支持吗?多谢
commit 94b8ac1
Merge: 8f2ef91 d42a1d9
Author: Marble Wu => 武眉博 / 活靶子 [email protected]
Date: Wed Sep 11 03:08:28 2013 -0700Merge pull request #3 from chaixl/runtime_dependency
Runtime dependency
remote: error: object 94b8ac1d59459f615aa83e177c3d76e210049169:invalid author/committer line - bad name
remote: fatal: Error in object
error: unpack failed: index-pack abnormal exit
To [email protected]:chaixl/carrierwave-qiniu.git
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to '[email protected]:chaixl/carrierwave-qiniu.git'
Bundler could not find compatible versions for gem "mime-types":
In Gemfile:
carrierwave-qiniu (>= 0) ruby depends on
qiniu (~> 6.4.1) ruby depends on
mime-types (~> 2.4.3) ruby
rails (= 4.1.5) ruby depends on
actionmailer (= 4.1.5) ruby depends on
mail (~> 2.5.4) ruby depends on
mime-types (1.25.1)
项目里一堆mime-types (~> 1.16)
,这可如何是好
其中 fileupload
class FileUploader < BaseUploader
def qiniu_persistent_ops
# commands = []
# binding.pry
end
def qiniu_async_ops
# binding.pry
commands = []
commands << "vframe/jpg/offset/7|saveas/111.jpg"
# commands << "" # if original_filename.include?('.mp4')
# commands << "avthumb/mp4"
# commands << "avthumb/m3u8/noDomain/1/segtime/15/vb/440k"
# commands
end
def qiniu_persistent_pipeline
'video_cover'
end
end
#<FileUploader:0x007f9a9f83bda0
@cache_id=nil,
@cache_storage=
#<CarrierWave::Storage::File:0x007f9a9cce71b8
@uploader=#<FileUploader:0x007f9a9f83bda0 ...>>,
@file=
#<CarrierWave::Storage::Qiniu::File:0x007f9a9ccd50d0
@path=
"uploads/nil_class//201806131558P5d18e5938a9d6eb92148b4ec79eec5ac.mp4",
@qiniu_connection=
#<CarrierWave::Storage::Qiniu::Connection:0x007f9a9ccd4608
@qiniu_access_key="v1cjPfe..........",
@qiniu_block_size=4194304,
@qiniu_bucket="assets",
@qiniu_bucket_domain="p63ldwakz.bkt.clouddn.com",
@qiniu_bucket_private=false,
@qiniu_callback_body="",
@qiniu_callback_url="",
@qiniu_can_overwrite=false,
@qiniu_delete_after_days=0,
@qiniu_expires_in=3600,
@qiniu_persistent_notify_url="",
@qiniu_persistent_ops="vframe/jpg/offset/7|saveas/111.jpg",
@qiniu_persistent_pipeline="video_cover",
@qiniu_private_url_expires_in=3600,
@qiniu_protocol="http",
@qiniu_secret_key="jXYG0wRRF........",
@qiniu_style_separator="-",
@qiniu_up_host=nil>,
@uploader=#<FileUploader:0x007f9a9f83bda0 ...>>,
@filename="aaa.mp4",
@model=nil,
@mounted_as=nil,
@original_filename="aaa.mp4",
@storage=
#<CarrierWave::Storage::Qiniu:0x007f9a9ccd6138
@uploader=#<FileUploader:0x007f9a9f83bda0 ...>>,
@versions={}>
Bundler::GemRequireError: There was an error while trying to load the gem 'carrierwave-qiniu'.
Gem Load Error is: undefined method `class_methods' for CarrierWave::Qiniu::Style:Module
Backtrace for gem load error is:
/Users/zmcNotafraid/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/carrierwave-qiniu-1.0.0/lib/carrierwave/qiniu/style.rb:8:in `<module:Style>'
/Users/zmcNotafraid/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/carrierwave-qiniu-1.0.0/lib/carrierwave/qiniu/style.rb:5:in `<module:Qiniu>'
/Users/zmcNotafraid/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/carrierwave-qiniu-1.0.0/lib/carrierwave/qiniu/style.rb:4:in `<module:CarrierWave>'
正常配置的,运行出现以上问题,carrierwave-qiniu 1.0.0 版本 ruby 2.2.0 rails 4.0.12
/usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'carrierwave-qiniu'. (Bundler::GemRequireError)
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/dks/project/process3D/config/application.rb:7:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `require'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
为什么用carrierwave-qiniu 上传图片后 服务器保存的图片名会比数据库里多uploads前缀,这个如何配置?我不想用uploads作为前缀 或者说我想设置自己的前缀
Qiniu
类单独出来,仅实现 Carrierwave 的 Abstract
Connection
类单独出来,仅作为调用七牛的 API 的 Wrapper File
类单独出来,仅用做 Object 的读写拷贝删除等Failure/Error: image.save
TypeError:
class or module required for rescue clause
# /home/ming/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/qiniu-rs-1.1.0/lib/qiniu/rs/auth.rb:64:in `rescue in request'
# /home/ming/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/qiniu-rs-1.1.0/lib/qiniu/rs/auth.rb:62:in `request'
# /home/ming/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/qiniu-rs-1.1.0/lib/qiniu/rs/rs.rb:27:in `publish'
# /home/ming/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/qiniu-rs-1.1.0/lib/qiniu/rs.rb:95:in `publish'
# /home/ming/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/carrierwave-qiniu-0.0.7.1/lib/carrierwave/storage/qiniu.rb:88:in `setup_publish_bucket_and_domain'
您好, 使用这个库时碰到到上述问题, 发现下面这行代码好像不行,
begin
code, data = Auth.call(url, data)
rescue [MissingAccessToken, MissingRefreshToken, MissingUsernameOrPassword] => e
Log.logger.error e
code, data = 401, {}
end
rescue 后面接的是数组貌似不行? 换成Exception => e
后旧可以了.
我是用的 ruby 2.2.2
对 CarrierWave 本身的裁切图片的
version :thumb do
process :resize_to_fill => [200, 200]
end
这个方法 是不是没有用了 也就是您本身并没有集成
报错信息:Upload failed, status code: 401, response: {"error"=>"bad token"}
配置:
::CarrierWave.configure do |config|
config.qiniu_access_key = ENV['QINIU_ACCESS_KEY'],
config.qiniu_secret_key = ENV['QINIU_SECRET_KEY'],
config.qiniu_bucket = ENV['QINIU_BUCKET'],
config.qiniu_bucket_domain = ENV['QINIU_BUCKET_DOMAIN'],
config.qiniu_bucket_private= true #default is false
config.qiniu_block_size = 4*1024*1024
config.qiniu_protocol = "http"
config.qiniu_up_host = "http://up.qiniu.com"
end
请问要在哪里配置 token ?
报错信息:
DEBUG -- : Query blogpic hosts Error: {}
W, [2017-06-19T12:12:25.934972 #43859] WARN -- : HTTP status code 612 => Qiniu::HTTP.get('http://uc.qbox.me/v1/query?ak=%5B%22GmjR1PC0QUbU0kCVAcOngOWlFbquRkfMoNr5HbxxxxxdWxxxxxx%22%2C%20%22blogxxxxxx20%22iduzqog.qiniudns.com%22%2xxxxx0false%5D&bucket=blogpic')
D, [2017-06-19T12:12:25.935323 #43859] DEBUG -- : Query blogpic hosts Error: {"error"=>"app/accesskey is not found"}
W, [2017-06-19T12:12:26.392624 #43859] WARN -- : 401 Unauthorized => Qiniu::HTTP.post('http://up.qiniu.com/')
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Bundler could not find compatible versions for gem "mime-types":
In Gemfile:
rails (= 3.2.21) ruby depends on
actionmailer (= 3.2.21) ruby depends on
mail (~> 2.5.4) ruby depends on
mime-types (~> 1.16) ruby
carrierwave-qiniu (= 0.1.6) ruby depends on
qiniu (~> 6.4.1) ruby depends on
mime-types (2.4.3)
看了华顺的这篇博客 http://huacnlee.com/blog/rails-app-image-store-with-carrierwave-upyun/ ,提供 user.avatar.url(:thumbnail)
这样的便利方法确实可以简化好多。结合目前的七牛图片样式的用法,我想到可以提供下面一组 api 来方便使用。目前这只是我的想法,我本地实验项目可以基本工作,后面提个PR看看如何。
class AvatarUploader < CarrierWave::Uploader::Base
# 第一种 通过 array 配置图片样式
qiniu_styles [:thumbnail, :large]
end
# 图片链接
user.avatar.url(:thumbnail)
# "http://..../avatar.jpg-thumbnail"
class AvatarUploader < CarrierWave::Uploader::Base
# 第二种 通过 hash 配置图片样式
qiniu_styles { thumbnail: "imageView2/0/w/200", large: "imageView2/0/w/800" }
end
user.avatar.url(:thumbnail)
# "http://..../avatar.jpg-thumbnail"
# 借助于qiniu可以直接在图片链接后面应用图片处理,这样图片样式可以不必事先添加就可以使用,尤其是在开发过程中比较方便
user.avatar.url(:thumbnail, inline: true)
# "http://..../avatar.jpg?imageView2/0/w/200"
# 第三种 直接使用图片处理
user.avatar.url(style: "imageView2/0/w/200")
# "http://..../avatar.jpg?imageView2/0/w/200"
借助于第二种配置方式,可以执行 rake carrierwave:qiniu:set_styles
借助七牛API 添加图片样式。
/Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- qiniu (LoadError)
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/carrierwave-qiniu-41f765a0f42f/lib/carrierwave/storage/qiniu.rb:3:in `<top (required)>'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/carrierwave-qiniu-41f765a0f42f/lib/carrierwave-qiniu.rb:2:in `<top (required)>'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:76:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:72:in `each'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:72:in `block in require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:61:in `each'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler/runtime.rb:61:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.10/lib/bundler.rb:134:in `require'
from /Users/hackerZhang/work/weddingServer/config/application.rb:7:in `<top (required)>'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `require'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `block in server'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/hackerZhang/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
GEM
# 七牛服务
gem 'qiniu', github: 'qiniu/ruby-sdk'
gem 'carrierwave'
gem 'carrierwave-qiniu', github: 'huobazi/carrierwave-qiniu'
报错信息如题!
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
gem 'carrierwave-qiniu', '~> 0.2.4'
image = Image.new
image.remote_image_url = "http://test.jpg"
image.save!
测试时使用remote_image_url的url值是可以访问的
做 rake assets:precompile 的时候会报错,仅在生产环境有问题。
报错如下:
rake aborted!
LoadError: cannot load such file -- qiniu
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/opt/www/ted/shared/bundle/ruby/2.1.0/bundler/gems/carrierwave-qiniu-faa990a733ae/lib/carrierwave/storage/qiniu.rb:3:in `<top (required)>'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/opt/www/ted/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/opt/www/ted/shared/bundle/ruby/2.1.0/bundler/gems/carrierwave-qiniu-faa990a733ae/lib/carrierwave-qiniu.rb:3:in `<top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:76:in `require'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:72:in `each'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:72:in `block in require'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:61:in `each'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler/runtime.rb:61:in `require'
/home/deployer/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.5/lib/bundler.rb:132:in `require'
/opt/www/ted/releases/20151217024839/config/application.rb:7:in `<top (required)>'
/opt/www/ted/releases/20151217024839/Rakefile:4:in `require'
/opt/www/ted/releases/20151217024839/Rakefile:4:in `<top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/home/deployer/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
@huobazi 麻烦看看。
错误信息如下
Error:[rake --tasks] rake aborted!
NameError: uninitialized constant CarrierWave::Storage::Qiniu::Connection::Carrierwave
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave/storage/qiniu.rb:77:in `<class:Connection>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave/storage/qiniu.rb:10:in `<class:Qiniu>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave/storage/qiniu.rb:8:in `<module:Storage>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave/storage/qiniu.rb:7:in `<module:CarrierWave>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave/storage/qiniu.rb:6:in `<top (required)>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/carrierwave-qiniu-0.1.8.1/lib/carrierwave-qiniu.rb:2:in `<top (required)>'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `require'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `each'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `block in require'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `each'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `require'
/Users/watsy/.rvm/gems/ruby-2.2.0/gems/bundler-1.10.4/lib/bundler.rb:134:in `require'
/Users/watsy/Documents/code/ruby/huaxing/unicornext/unicornext/config/application.rb:10:in `<top (required)>'
/Users/watsy/Documents/code/ruby/huaxing/unicornext/unicornext/Rakefile:4:in `require'
/Users/watsy/Documents/code/ruby/huaxing/unicornext/unicornext/Rakefile:4:in `<top (required)>'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/watsy/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/watsy/Documents/code/ruby/huaxing/unicornext/unicornext/bin/rake:8:in `<main>'
gemfile.lock中信息如下
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
carrierwave-qiniu (0.1.8.1)
carrierwave
qiniu (~> 6.4.2)
[2] pry(main)> s.icon.url
=> "http://7xivnf.com2.z0.glb.qiniucdn.com/uploads%2Fseries%2Ficon%2F1%2F201242411445734.jpg"
其中路径中的“/”被转义成了“%2F”
项目的图片是private的,但同时希望能做处理,不知道如何能构建这样的加密url?
http://qiniuphotos.qiniudn.com/gogopher.jpg?imageView2/1/w/200/h/200&e=xxxx&token=yyy
查看了源码,但还是没有头绪。
以Carrierwave的风格,要raise也是在store!里raise
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.