25

I have video model with the following definition:

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

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.

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

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'
)

Is it possible to assign files like this to Carrierwave?

3
  • You watch railscasts, don't you? ;) Did you use paperclip before? Which one do you prefer?
    – Robin
    Feb 15, 2011 at 18:15
  • 1
    Hi Robin, tried Paperclip. I prefer Carrierwave. Just a personal preference :-) Feb 15, 2011 at 18:28
  • 1
    Check out the answer here. update_column skips callbacks allowing you to update the attribute without having CarrierWave re-upload the image. stackoverflow.com/questions/16968658/…
    – pejmanjohn
    Aug 22, 2013 at 22:41

4 Answers 4

50

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.

11
  • 1
    Why would "@video.remote_attachment_thumnail_url" cause Carrierwave to download + reprocess the file? Feb 15, 2011 at 18:28
  • 1
    You're just telling carrierwave to grab the file from there vs. having the file uploaded. It's generally used in forms for the user to enter a URL to an image that they'd like to upload.
    – ctide
    Feb 15, 2011 at 19:58
  • ctide, I just tried: @video.update_attributes(:attachment_thumbnail => 'bucket_name.s3.amazonaws.com/uploads/users/1/video/1/…) and I get: CarrierWave::FormNotMultipart: CarrierWave::FormNotMultipart. I guess you can't do @video.remote_attachment_thumnail_url = 'bucket_name.s3.amazonaws.com/uploads/users/1/video/1/thumb.png', which is merely the same thing. Or am I missing something? Feb 15, 2011 at 21:30
  • 5
    It's not the same thing, remote_[uploader]_url is an instance method that tells Carrierwave to download the file from that URL. See: github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/… line 87 Also, it's not an attribute, so you can't set it via update_attributes.
    – ctide
    Feb 15, 2011 at 22:22
  • 2
    Is it possible to assign the remote file to CarrierWave only? This means not for it to download or reprocess, just assign. So that I may utilize the helper as such: @video_attachment_thumbnail.url Feb 18, 2011 at 5:58
11

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.