【问题标题】:Get Filepath from uploaded file on Google Cloud Storage从 Google Cloud Storage 上上传的文件中获取文件路径
【发布时间】:2019-11-25 14:23:38
【问题描述】:

我刚刚将我的应用程序配置为使用 Google Cloud Storage 来存储用户上传的内容。到目前为止,我能够通过这样做检索上传的文件路径:

ActiveStorage::Blob.service.send(:path_for, file.key)

但是,在 Google Cloud Storage 上,这给了我以下错误:

NoMethodError (undefined method `path_for' for #<ActiveStorage::Service::GCSService:...>)

如何在此处检索文件路径?

【问题讨论】:

  • 这可能是因为他们不希望您在底层操作系统层上工作?所以我的猜测是你不能,如果你确实找到了一种方法,那将是一个黑客,在未来的某个时候会被关闭。
  • @ekampp 你可能是对的

标签: google-cloud-storage rails-activestorage ruby-on-rails-6


【解决方案1】:

您可以使用url_for_direct_upload(key, expires_in:, checksum:, **)url(key, expires_in:, filename:, content_type:, disposition:) 获取GCS url。

Reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-22
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    相关资源
    最近更新 更多