Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3.1 Rails-对用户隐藏文件url(Rails 3.1+;carrierwave+;开发者谷歌存储)_Ruby On Rails 3.1_Google Cloud Storage - Fatal编程技术网

Ruby on rails 3.1 Rails-对用户隐藏文件url(Rails 3.1+;carrierwave+;开发者谷歌存储)

Ruby on rails 3.1 Rails-对用户隐藏文件url(Rails 3.1+;carrierwave+;开发者谷歌存储),ruby-on-rails-3.1,google-cloud-storage,Ruby On Rails 3.1,Google Cloud Storage,我已经构建了一个部署在heroku上的应用程序,它使用carrierwave来保存所有上传的文件,并且我已经为开发者设置了google存储来保存这些文件 在此之前,一切正常,但我想保持文件显示的隐私,即用户必须有权查看。 在开发环境中,一切都很好 为了对用户隐藏文件源url,我做出了以下决定: 初始化者/carrierwave.rb CarrierWave.configure do |config| if Rails.env.production? config.storage =

我已经构建了一个部署在heroku上的应用程序,它使用carrierwave来保存所有上传的文件,并且我已经为开发者设置了google存储来保存这些文件

在此之前,一切正常,但我想保持文件显示的隐私,即用户必须有权查看。 在开发环境中,一切都很好

为了对用户隐藏文件源url,我做出了以下决定:

初始化者/carrierwave.rb

CarrierWave.configure do |config|
  if Rails.env.production?
    config.storage = :fog
    config.fog_credentials = {
      :provider                         => 'Google',
      :google_storage_access_key_id     => 'xxx',
      :google_storage_secret_access_key => 'yyy'
    }
    config.fog_directory = 'wwww'
  else
    config.storage = :file
  end
end
控制器

这会获取文件内容,以便对公众隐藏其路径和名称

def get_file
  if Rails.env.production?
    redirect_to URI.encode @media_asset.attachment_url
  else
    send_file ("public/"+@media_asset.attachment_url.to_s), 
          :type => @media_asset.attachment_content_type,
          :length => @media_asset.attachment_file_size,
          :status => "200 OK",
          :x_sendfile => true,
          :filename => "media_asset",
          :disposition => 'inline'
  end
end
显然,这可以完成这项工作,但使用普通的浏览器开发工具,每个人都可以看到谷歌存储桶的路径,并能够访问所有文件

你对如何解决这个问题有什么线索吗?甚至可以为开发者使用谷歌存储吗


提前感谢,

您的用户有谷歌账户吗?如果是这样,您可以使用经过身份验证的下载机制:


您可以使用新发布的签名URL功能(https://developers.google.com/storage/docs/accesscontrol#Signed-URL)在谷歌云存储中实现这一点。

我们的想法是拥有应用程序帐户。实际上,我正在使用Desive作为认证宝石,稍后的目标是拥有多个登录选项,如facebook、twitter、google等。。。但目前最重要的是要有应用程序用户。我转向了s3,我仍然在解决这个问题。虽然答案并不正确,但我会接受它,因为我想转移到另一家云存储提供商。