如何分配一个远程文件Carrierwave?分配、文件、Carrierwave

2023-09-11 23:38:11 作者:假裝狠快樂

我有如下定义视频模式:

I have video model with the following definition:

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

当我上传的视频文件。它也将文件发送到我们​​的服务编码禅宗codeR,这EN codeS的视频文件,并为它创建一个缩略图。

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.

 
精彩推荐
图片推荐