Closed jhorsch closed 9 years ago
What happens if you save the photo after setting the key?
def perform(photo_id, image_key)
photo = Photo.find(photo_id)
photo.key = image_key
photo.save!
photo.remote_image_url = photo.image.direct_fog_url(:with_path => true)
binding.pry
photo.save!
end
I keep getting the same issue ActiveRecord::RecordInvalid: Validation failed: Image attachment is missing
This worked with Sidekiq
def create if new_photo(photo_params).save(validate: false) UploadsWorker.perform_async(new_photo.id, new_photo.key) end end
def perform(photo_id, image_key) photo = Photo.find(photo_id) uploaded_photo_path = photo.image.direct_fog_url(:with_path => false).to_s + image_key.to_s photo.remote_image_url = uploaded_photo_path photo.save end
Glad you got it solved.
Hi,
I am trying to understand why the direct_fog_url returns the path to my default url instead of the path to my uploaded image 'med_res.jpg' with the following key
ImageUploader.rb def default_url "https://s3-us-west-2.amazonaws.com/luminoto/worlds_first_camera.jpg" end
UploadsWorker.rb def perform(photo_id, image_key) photo = Photo.find(photo_id) photo.key = image_key photo.remote_image_url = photo.image.direct_fog_url(:with_path => true) binding.pry photo.save! end
console [6] pry(#)> photo.key
=> "development/photo/image/8b6ad024-adaa-4f0e-af71-d4f12c9f288f/med_res.jpg"
[7] pry(#)> photo.image.direct_fog_url(:with_path => true)
=> "https://d9vwx0ll7rhpx.cloudfront.net/uploads/tmp/1427316979-29456-6641/default_image.jpg"