如何将远程文件分配给 Carrierwave? [英] How to assign a remote file to Carrierwave?

查看:36
本文介绍了如何将远程文件分配给 Carrierwave?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下定义的视频模型:

I have video model with the following definition:

class Video
  require 'carrierwave/orm/activerecord'
  mount_uploader :attachment, VideoUploader
  mount_uploader :attachment_thumbnail, VideoThumbnailUploader
  ...
end

当我上传视频文件时.它还将文件发送到我们的编码服务 Zencoder,后者对视频文件进行编码并为其创建缩略图.

When I upload a video file. It also sends the file to our encoding service Zencoder, which encodes the video file and creates a thumbnail for it.

通常,我可以执行类似@video.attachment.url 的操作,它会返回视频文件的路径.我想对缩略图做同样的事情.即@video.attachment_thumbnail.url

Normally, I could do something like @video.attachment.url, which will return the path of the video file. I'd like to do the same thing with the thumbnail. i.e. @video.attachment_thumbnail.url

但是,由于附件是由我们的编码服务创建的,它也会将其上传到指定的 S3 存储桶.如何将附件分配给记录的附件缩略图列?

However, since the attachment is created by our encoding service, which also uploads it to a specified S3 bucket. How do I assign the attachment to the attachment_thumbnail column for the record?

我可以简单地做一些类似的事情:

Can I simply do something like:

@video.update_attributes(
  :attachment_thumbnail => 'https://bucket_name.s3.amazonaws.com/uploads/users/1/video/1/thumb.png'
)

是否可以将这样的文件分配给 Carrierwave?

Is it possible to assign files like this to Carrierwave?

推荐答案

您可以执行以下操作:

@video.remote_attachment_thumbnail_url = 'https://bucket_name.s3.amazonaws.com/uploads/users/1/video/1/thumb.png'

但这会导致 Carrierwave 下载并重新处理文件,而不仅仅是将其设为缩略图.如果您不打算使用 Carrierwave 的处理,那么将 URL 存储到模型上的缩略图可能比使用 Carrierwave 更有意义.

But that will cause Carrierwave to download + reprocess the file rather than just make it the thumbnail. If you're not going to use Carrierwave's processing, then it might make more sense to just store the URL to the thumbnail on the model rather than even using Carrierwave.

这篇关于如何将远程文件分配给 Carrierwave?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆