How to assign a remote file to Carrierwave?

后端 未结 4 1535
感情败类
感情败类 2020-12-08 01:19

I have video model with the following definition:

class Video
  require \'carrierwave/orm/activerecord\'
  mount_uploader :attachment, VideoUploader
  mount_         


        
相关标签:
4条回答
  • 2020-12-08 01:27

    You can do the following:

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

    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.

    0 讨论(0)
  • 2020-12-08 01:28

    I was looking for this as well.

    The blocking point in the zencoder case would be that Carrierwave doesn't track different different file type versions for the original file. It only references the original file.

    So having the original file as an .mp4 a a thumbnail version as a .png doesn't work. While you can have an 'image.png' and also track 'thumb_png_image.png', you can't also create a 'thumb_jpg_image.jpg' for the same file.

    Otherwise you could create a dummy version and using conditional versioning tell CW not to process it. Since CW would create the dummy version anyway but not upload it, you could have it reference a path matching the file returned by Zencoder. But oh well...

    0 讨论(0)
  • 2020-12-08 01:31

    At the end of this episode (7:35), Ryan Bates adds a remote_image_url in a file form upload:

    http://railscasts.com/episodes/253-carrierwave-file-uploads

    0 讨论(0)
  • 2020-12-08 01:48

    This worked for me, with CarrierWave 0.5.8

    model.update_attributes(:remote_uploader_url => "http://path/to/image.jpg")
    

    Of course, you need to set remote_uploader_url to be attr_accessible for this.

    0 讨论(0)
提交回复
热议问题