Comments (9)
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.
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.
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.
Please make sure after_save is placed after the mount_uploader definition (otherwise the callbacks are called in the wrong order).
from cloudinary_gem.
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.
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.
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.
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.
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)
- How to pass options to ActiveStorage upload? HOT 3
- Cant direct upload raw files HOT 17
- Some kind of overlay texts generate urls which cause `400 Bad Request` HOT 7
- Support Dynamic Folder upload parameters HOT 2
- How to get value txt file? HOT 3
- Update API is missing metadata support HOT 3
- Conditional metadata rules support HOT 6
- Broken urls - Unsafe characters in public_id are not properly escaped by Cloudinary::Utils.cloudinary_url HOT 2
- Photo metadata is nil until after AR callbacks have run HOT 7
- Unable to upload multiple images to cloudinary HOT 1
- ActiveStorage: Non-image file is not deleted when its blob is destroyed HOT 4
- ActiveStorage support for upload_large HOT 2
- Update sample projects dependencies HOT 4
- preview:duration effect was shortened to preview:du when uploading a video HOT 1
- Access token url generation returns 404 HOT 2
- The gem breaks the lazy loading of ActionView::Base HOT 1
- Contextual metadata support for url_for_direct_upload HOT 2
- Invalid Remote Fetch URL if `folder` is set in Storage Service Config HOT 9
- Transformation params not properly URL escaped HOT 3
- 2.0: Rake task fail with `LoadError` on `faraday/follow_redirects` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudinary_gem.