Giter Club home page Giter Club logo

Comments (9)

ehoch avatar ehoch commented on May 23, 2024

Pinging this one. Would it be possible to add an easy way to get the width / height from the uploaded JSON for those of us that store that in the model?

from cloudinary_gem.

TalLevAmi avatar TalLevAmi commented on May 23, 2024

All the metadata returned from Cloudinary can be accessed right after the upload using the metadata method on the uploader. You can add the following to your model to retrieve the width and height (picture is the name of mounted upload) -

after_save :update_dimensions

def update_dimensions
  if self.picture.present? && self.picture.metadata.present?
    width = self.picture.metadata["width"]
    height = self.picture.metadata["height"]
    # TODO: Update model entity
  end
end

from cloudinary_gem.

ehoch avatar ehoch commented on May 23, 2024

metadata is nil for me... I have an extremely basic uploader:

class ImageUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave
  def public_id
    "#{model.class.to_s}-#{model.slug}"
  end
end

And mounted:

class Photo < ActiveRecord::Base
  mount_uploader :image, ImageUploader
end

I've tried both before_save and after_save. On both of them image.metadata is nil...

from cloudinary_gem.

TalLevAmi avatar TalLevAmi commented on May 23, 2024

Please make sure after_save is placed after the mount_uploader definition (otherwise the callbacks are called in the wrong order).

from cloudinary_gem.

ehoch avatar ehoch commented on May 23, 2024

It is. The mount_uploader is at the very top of my model definition and I tried callback at bottom. It seems to be getting cleared out.

from cloudinary_gem.

TalLevAmi avatar TalLevAmi commented on May 23, 2024

Can you please try to add the following to the end of the Photo class:

after_save :testmd
def testmd
  puts "HERE #{self.image.metadata.inspect}"
end

And upload using the rails console:

Photo.create(:remote_image_url=>"http://cloudinary.com/images/logo.png")

from cloudinary_gem.

ehoch avatar ehoch commented on May 23, 2024

Weird. I must have something conflicting with it:

/Users/ehochber/.rvm/gems/ruby-2.0.0-p0@thg/gems/activerecord-3.2.13/lib/active_record/persistence.rb:85
rescue ActiveRecord::RecordInvalid

from cloudinary_gem.

TalLevAmi avatar TalLevAmi commented on May 23, 2024

Maybe you have :null=>false fields in the photos table?
If remote_image_url is the issue, you can try uploading a local file:

Photo.create(:image_url=>File.open("Path to local image file"))

from cloudinary_gem.

ehoch avatar ehoch commented on May 23, 2024

Fantastic! I tried this on a simper model and it worked. Looks like some of my method aliasing I use to detect image changes were conflicting. Thanks!

from cloudinary_gem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.