Yur*_*ert 9 ruby-on-rails carrierwave fog google-cloud-storage google-cloud-platform
我正在使用Carrierwave和Fog将图像存储在云端.我以前使用Amazon S3进行实际存储,没有任何问题.但是我切换到Google云端存储,现在每当我尝试保存任何内容时,我都会收到以下错误:
Excon :: Error ::禁止在GalleriesController中创建
预期(200)<=>实际(403禁止)excon.error.response:body =>"
__CODE__提供的安全凭证无效.请求未签名或包含格式错误的签名":cookies => []:headers => {"Alt-Svc"=>"hq = \":443 \"; ma = 2592000; quic = 51303433; quic = 51303432; quic = 51303431; quic = 51303339; quic = 51303335,quic = \":443 \" ; ma = 2592000; v = \"43,42,39,38,35 \"""Content-Length"=>"224""Content-Type"=>"application/xml; charset = UTF-8""日期"=>"星期二,2018年5月1日22:03:23 GMT""服务器"=>"UploadServer""Vary"=>"Origin""X-GUploader-UploadID"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}:host => "[directory] .storage.googleapis.com":local_address =>"xxx.xxx.x.xxx":local_port => xxxxx:path =>"/ uploads%2Fimage.png":port => 443:reason_phrase => "Forbidden":remote_ip =>"xxx.xxx.x.xx":status => 403:status_line =>"HTTP/1.1 403 Forbidden\r \n"
初始化/ carrierwave.rb
CarrierWave.configure do |config|
config.fog_provider = 'fog/google'
config.fog_credentials = {
provider: 'Google',
google_storage_access_key_id: 'GOOGxxxxxxxxxxx',
google_storage_secret_access_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
config.fog_directory = 'xxxxxxxxxxx'
#config.fog_public = false
#config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" }
end
Run Code Online (Sandbox Code Playgroud)
上传
class PhotoFileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def fix_exif_rotation
manipulate! do |img|
img.tap(&:auto_orient)
end
end
process :fix_exif_rotation
process :resize_to_fit => [800, 56000]
version :thumb do
process resize_to_fit: [300, 56000]
end
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile
gem "fog-google"
gem "google-api-client", "> 0.8.5", "< 0.9"
gem "mime-types"
Run Code Online (Sandbox Code Playgroud)
似乎key_id或secret_key存在问题,但我只是从Google云存储设置页面上的互操作性部分复制并粘贴了两者.我不知道如何测试它们是否有效.如果重要的话,我的请求来自localhost.
我在SO上发现了一些类似的错误,但它们都与亚马逊有关,而且它们似乎并不适用于我正在做的事情.
任何人对我如何调试这个有任何想法?
您应该在 for_directory 中使用有效的目录名称。
config.fog_directory = '[directory]'
用。。。来代替config.fog_directory = 'name_of_fog_folder'。
希望这会有所帮助。
| 归档时间: |
|
| 查看次数: |
464 次 |
| 最近记录: |