huacnlee / carrierwave-aliyun

阿里云 OSS Ruby 上传组件,基于 Carrierwave
https://huacnlee.com/carrierwave-aliyun/
197 stars 93 forks source link

No implicit conversion of nil into String #20

Closed victorteokw closed 9 years ago

victorteokw commented 9 years ago

Thanks for your brilliant gem package.

When I was uploading file, I got an error from this gem package.

no implicit conversion of nil into String

carrierwave/storage/aliyun.rb:136:in `digest'
carrierwave/storage/aliyun.rb:136:in `sign'
carrierwave/storage/aliyun.rb:55:in `put'
carrierwave/storage/aliyun.rb:200:in `store'
carrierwave/storage/aliyun.rb:232:in `store!'
carrierwave (0.10.0) lib/carrierwave/uploader/store.rb:59:in `block in store!'

My config is totally correct, and rigidly followed the instruction described in README.md

CarrierWave.configure do |config|
  config.storage = :aliyun
  config.aliyun_access_id = "my_access_id"
  config.aliyun_access_key = "my_access_key"
  config.aliyun_bucket = "my_bucket"
end

And my uploader:

class ImageUploader < CarrierWave::Uploader::Base
  storage :aliyun
end
liwei78 commented 9 years ago

@cheunghy You can gem 'carrierwave-aliyun', github: "huacnlee/carrierwave-aliyun"

ruby 2.2.0 have removed Digest::HMAC, but rubygems not update. https://github.com/ruby/ruby/blob/v2_2_0/NEWS#L146

I saw the https://github.com/huacnlee/carrierwave-aliyun/commit/b3099aa76d29eee595c13dcb7fa1d7596772f335 , I suggest @huacnlee update version to 0.3.4 to support ruby 2.2.0.

victorteokw commented 9 years ago

@liwei78 Thanks a lot!

That's not the case. Even though that issue is fixed, this issue still occurs.

huacnlee commented 9 years ago

Just released 0.3.4

victorteokw commented 9 years ago

Thanks, Jason.

That's not the same case.

This issue still exists.

Can we find some official help from aliyun?

huacnlee commented 9 years ago

请在 bundle open carrierwave-aliyun 并在 lib/carrierwave/storage/aliyun.rb#L136 行 h = OpenSSL::HMAC.digest(digest, @aliyun_access_key, string_to_sign) 前面增加一个 puts 打印信息看看

puts "digest: #{digest}    aliyun_access_key: #{@aliyun_access_key}   string_to_sign: #{string_to_sign}"
h = OpenSSL::HMAC.digest(digest, @aliyun_access_key, string_to_sign)
victorteokw commented 9 years ago

Thanks.

digest: da39a3xx5e6b4b0d3255bfef95xx1890afd80709    aliyun_access_key:    string_to_sign: PUT
victorteokw commented 9 years ago

My config is fine

CarrierWave.configure do |config|
  config.storage = :aliyun
  config.aliyun_access_id = "CFbiFxxMxrGugKxx"
  config.aliyun_access_key = "L1IH5VhS54xxH7J3dFOxniboIdfQxx"
  config.aliyun_bucket = "xxxxdxrt"
end
huacnlee commented 9 years ago

@cheunghy 这个配置信息你放在哪儿的?

victorteokw commented 9 years ago

/path/to/my/rails_project/config/carrierwave.rb

huacnlee commented 9 years ago

放到 rails_project/config/initializes 下面

victorteokw commented 9 years ago

Oh my bad. Thanks a lot.

fronzethrone commented 9 years ago

@huacnlee 我放在ails_project/config/initializes下面,配置也ok, 在代码中,这样如下使用: connection = CarrierWave::Storage::Aliyun::Connection.new tmp_file = open_tmp_file url = connection.put(filename,tmp_file) 也是出现同样的问题,加了打印纸后,如下: digest: da39a3ee5e6b4b0d3255bfef95601890afd80709 aliyun_access_key: string_to_sign: PUT

fronzethrone commented 9 years ago

@huacnlee @cheunghy 在设置了bucket为private之后,不能够通过connection.get(file_path)能获取么,我get文件时候提示为403 Forbidden,需要做什么配置么

huacnlee commented 9 years ago

没试过,不确定

在 2015年3月25日,19:08,fronzethrone notifications@github.com 写道:

@huacnlee @cheunghy 在设置了bucket为private之后,不能够通过connection.get(file_path)能获取么,我get文件时候提示为403 Forbidden,需要做什么配置么

— Reply to this email directly or view it on GitHub.

fronzethrone commented 9 years ago

@huacnlee ,两个问题都解决了,第一个是因为代码里面没有设置默认值,需要把配置文件读出来作参数传给connection,第二个问题是因为你的gem里面的get 方法没有经过认证,默认文件是public权限来的。加上认证那段就可以了,非常谢谢你的gem包,嘿嘿!