Carrierwave

编程入门 行业动态 更新时间:2024-10-16 22:18:48
Carrierwave - 保存为S3作为独立操作(Carrierwave - Save to S3 as an independent action)

我的用户存储外部图像URL(http://their-site.com/photo.jpg) - 例如 - @user.external_image 。 我正在尝试为User类编写一个方法,该方法使用Carrierwave将该URL保存到S3。

所以在上面的@user ,我想运行@user.save_to_s3并让它将图像“上传”到S3。 我试图通过在:s3_image添加一个上传器:s3_image到User类并编写以下方法:

def save_to_s3 self.remote_s3_image_url = self.external_image save end

但是当我在@user记录上调用该方法时,我收到以下错误:

“ArgumentError:缺少必需的参数:aws_access_key_id,aws_secret_access_key”

所以它越来越近了,但它并没有检索我的S3凭证 - 即使它们被设置了。 我很感激任何想法或建议。

My users store an external image URL (http://their-site.com/photo.jpg) in - for example - @user.external_image. I'm trying to write a method for the User class that takes that URL and saves it to S3 using Carrierwave.

So on the above @user, I'd like to run @user.save_to_s3 and have it "upload" the image to S3. I've tried to do this by mounting an uploader on :s3_image to the User class and writing the following method:

def save_to_s3 self.remote_s3_image_url = self.external_image save end

But I get the following error when I call that method on a @user record:

"ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key"

So it's getting close, but it's not retrieving my S3 credentials - even though they're set. I'd appreciate any thoughts or suggestions.

最满意答案

事实证明这个问题与Carrierwave或Fog无关。 这是我的疏忽,我设置的ENV变量(在我的应用程序的.env文件中)没有被加载到自举Rails环境(例如rails控制台)。 一旦我将http://github.com/bkeepers/dotenv (它正好解决了这个问题)添加到我的包中, save_to_s3方法就可以了。

The problem turned out to be unrelated to Carrierwave or Fog. It was an oversight on my part that the ENV variables which I'd set (in my app's .env file) were not being loaded into the bootstrapped Rails environment (e.g. rails console). Once I added http://github.com/bkeepers/dotenv (which solves precisely that issue) to my bundle, the save_to_s3 method worked.

更多推荐

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

发布评论

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

>www.elefans.com

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