vendredi 20 octobre 2017

Carrierwave filename method creating issue when uploading file to s3

I have an ImageUploader. And want to upload image into S3. Also change filename using filename method. Here the code:

class ImageUploader < CarrierWave::Uploader::Base

storage :fog

  def store_dir
    "images"
  end

  def filename
    "#{model.id}_#{SecureRandom.urlsafe_base64(5)}.#{file.extension}" if     original_filename
  end
end

First time when I save an image to model then it will give correct filename e.g 1_23434.png

But when I get the model object from the terminal console then it will return different image name and changed image name.

Is there anyone here who can tell me what I do? It works fine when I do not use fog.

Aucun commentaire:

Enregistrer un commentaire