views:

19

answers:

1

Hi guys,

I am building a Rails application that works with videos. I am using an encoding service that encodes my video and places the encoded file along with some thumbnails in a specified location on my s3. I am able to access the video via AWS:S3 like so:

AWS::S3::S3Object.find 'videos/36/base/video.mp4', 'my-bucket-name'

-- or --

AWS::S3::S3Object.value 'videos/36/base/video.mp4', 'my-bucket-name'

What I would like to do is manage these files with Paperclip once I get notified from my encoding service that the encoding is complete. Not sure how to do this. Here is what I have so far:

class Encoding << ActiveRecord::Base

   has_attached_file :video,
                :url => ':s3_domain_url',
                :path => 'videos/:video_id/:encoding_type/basename.:extension',
                :storage => :s3,
                :s3_credentials => {:access_key_id => AppConfig.s3.access_key_id,
                                    :secret_access_key => AppConfig.s3.secret_access_key,
                                    :bucket => AppConfig.s3.bucket
                },
                :s3_permissions => 'authenticated-read',
                :s3_protocol => 'http'
end

class Video << ActiveRecord::Base
  def after_encoded
     encoding = encodings.build
     encoding.video = ## WHAT GOES HERE ??
     encoding.save
  end
end

Thanks! Really appreciate your help

-- jonathan

A: 

I figured out how to do this. Simplely set the the paperclip attributes directly. So my after_encoded method looks like this

   def after_encoded
     encoding = encodings.build
     encoding.video_file_name = @video_details['url'].split('/').last
     encoding.video_content_type = MIME::Types.type_for(encoding.video_file_name).to_s
     encoding.video_file_size =  @video_details['size']
     encoding.video_updated_at = Time.now
     encoding.save
   end

Works great

Jonathan