Carrierwave/Fog Ruby on Rails gem 不会将文件上传到 Amazon S3

编程入门 行业动态 更新时间:2024-10-17 00:20:37
本文介绍了Carrierwave/Fog Ruby on Rails gem 不会将文件上传到 Amazon S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经浏览了 railscast 并在 StackOverflow 上进行了研究.虽然我发现其他人也有同样的问题,但我研究过的任何其他解决方案似乎都不起作用.我已经尝试了其他帖子中建议的代码的多种变体......没有运气.

I have gone through the railscast and researched here on Stack Overflow. Although I have found others with the same issue, it doesn't appear that any of the other solutions I have researched seem to work. I have tried multiple variations of the code as suggested in other posts... No luck.

我正在尝试通过 将 PDF 文件上传和存储到 Amazon S3Carrierwave 和 Fog 宝石无济于事.当我在生产中使用 Heroku 时,我还没有尝试将它部署到 Heroku,因为我甚至不能让它在本地工作.返回的错误是

I am attempting to upload and store PDF files to Amazon S3 via the Carrierwave and Fog gems to no avail. While I am using Heroku in production, I have not attempted to deploy this to Heroku yet since I cannot even get this to work locally. The error returned is

缺少必需的参数:aws_access_key_id、aws_secret_access_key

Missing required arguments: aws_access_key_id, aws_secret_access_key

我该如何解决这个问题?

How can I fix this problem?

CarrierWave.configure do |config| config.fog_credentials = { provider: 'AWS', aws_access_key_id: ENV['MY_KEY_ID'], aws_secret_access_key: ENV['MY_KEY'] } config.fog_directory = ENV['MY_BUCKET'] config.fog_public = false end

pdf_uploader.rb:

pdf_uploader.rb:

class PdfUploader < CarrierWave::Uploader::Base storage :fog include CarrierWave::MimeTypes process :set_content_type def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end

推荐答案

将 key_id、key AND 存储桶设置为环境变量时似乎存在问题.一旦我将所有三个更改为字符串常量,它似乎工作正常.我还部署到 Heroku 并在生产中验证了功能.

It looks like there was an issue with setting the key_id, key AND bucket as environmental variables. Once I changed all three to string constants, it seemed to work fine. I also deployed to Heroku and verified functionality in production as well.

最终的初始化文件:

CarrierWave.configure do |config| config.storage = :fog config.fog_credentials = { provider: 'AWS', aws_access_key_id: 'MY_KEY_ID_HERE', aws_secret_access_key: 'MY_KEY_HERE' } config.fog_directory = 'MY_S3_BUCKET_HERE' config.fog_public = false end

更多推荐

Carrierwave/Fog Ruby on Rails gem 不会将文件上传到 Amazon S3

本文发布于:2023-11-24 04:47:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会将   文件上传   Ruby   Fog   Carrierwave

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!