dwilkie / carrierwave_direct

Process your uploads in the background by uploading directly to S3
MIT License
839 stars 181 forks source link

direct_fog_url being set to carrierwave default_image instead of image uploaded #176

Closed jhorsch closed 9 years ago

jhorsch commented 9 years ago

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"

p8 commented 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
jhorsch commented 9 years ago

I keep getting the same issue ActiveRecord::RecordInvalid: Validation failed: Image attachment is missing

jhorsch commented 9 years ago

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

p8 commented 9 years ago

Glad you got it solved.