gogocarl / paperclip-cloudinary Goto Github PK
View Code? Open in Web Editor NEWStore Paperclip-managed assets with Cloudinary.
License: MIT License
Store Paperclip-managed assets with Cloudinary.
License: MIT License
I get the Cannot load storage module 'Cloudinary' error when trying to use paperclip-cloudinary.I have the cloudinary credentials at config/cloudinary.yml and th flie that holds the cloudinary info is as below
class Photo < ApplicationRecord
belongs_to :user
has_attached_file :image,
storage: :cloudinary
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
Can you tell me how change the resource_type (for video by example).
I tried this one but it doesn't work :
o.animation.url :original, {:resource_type => :video}
"http://res.cloudinary.com/vdcl6vbxx/image/upload/overlay_90aa2ab0-1ae8-0134-7d7c-0242ac110001.webm"
BTW, i think somethings is wrong with the "url" method :
def url style_or_options = default_style, options = {}
if style_or_options.is_a?(Hash)
options.merge! style_or_options
style = default_style
else
style = style_or_options
end
::Cloudinary::Utils.cloudinary_url path(style)
end
options is never used in Cloudinary::Utils.cloudinary_url ?!
and i'm not sure to undestrand the aim of "style" parameter (and "default_style").
Thx
Hi,
I'm currently using Paperclip with s3 storage, and changing default settings to cloudinary storage - following paperclip-cloudinary readme - leads to the error below. Any idea where to go from here?
Thanks!
Paperclip::Errors::InfiniteInterpolationError - Paperclip::Errors::InfiniteInterpolationError: () Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/interpolations.rb:53:in
url'
() Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/interpolations.rb:34:in block (2 levels) in interpolate' () Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/interpolations.rb:33:in
block in interpolate'
() Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/interpolations.rb:32:in interpolate' () Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/attachment.rb:544:in
interpolate'
() Users/lucas/.rvm/gems/ruby-2.2.2/bundler/gems/paperclip-97c78efdce65/lib/paperclip/attachment.rb:166:in path' paperclip-cloudinary (1.1.0) lib/paperclip/storage/cloudinary.rb:71:in
url'`
Hi there, I configured for my image like this:
class Image < ApplicationRecord
default_scope { where.not(photo_file_name: [nil, ""]).where.not(photo_content_type: [nil, ""]) }
belongs_to :article, optional: true
after_save :delete_invalid_image
has_attached_file :photo, :storage => :cloudinary, path: "/uploaded/:class/:attachment/:id/:style_:filename", styles: { thumb: "300x200#", large: "1024x768>"}
validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/
#attr_accessor :photo
def original_photo_url
photo.path(:large, timestamp: false)
end
paginates_per 30
private
def delete_invalid_image
if !photo?
self.destroy
end
end
end
and when I check method delete_invalid_image
it always returns nil
, and this cause a problem that I cannot upload the new image(this happened after I added cloudinary gem). Please let me know what I was wrong here.
I already had Paperclip running, what do I need to modify besides the model to work correctly as Cloudinary? I have this error, but I have not changed anything in the controller and the view.
Example of how the controller would look
i have my model:
class Chef < ApplicationRecord
belongs_to :restaurant
validates :name, presence: true
validates :avatar,
attachment_content_type: { content_type: /\Aimage\/.*\Z/ },
attachment_size: { less_than: 5.megabytes },
has_attached_file :avatar,
:storage => :cloudinary
end
and it give me this error
syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' has_attached_file :avatar, ^
in this line
has_attached_file :avatar,
Lambdas don't seem to properly execute when they do not conflict in the deep merge process. Ensure that they always run, while continuing to support nested lambdas.
I have this style on the images
has_attached_file :avatar,
:storage => :cloudinary,
:path => "dishes/:filename",
:styles => {
:thumb => '100x100>',
:square => '200x200#',
:medium => '300x300>'
}
and then i call them like this:
<%= image_tag dish.avatar.url(:medium), :class => 'img-responsive imgCenter' %>
but its not showing the right size
Given the following code:
class User < ApplicationRecord
has_attached_file :avatar,
styles: { medium: "300x300>", thumb: "100x100>" },
default_url: "/images/:style/missing.png",
storage: :cloudinary,
path: ":class/:attachment/:id_partition/:style/:filename"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\z/
end
If a user does not have an avatar, call the method url
on avatar will return nil
instead the default url.
User.first.avatar.url
> nil
It should return:
User.first.avatar.url
> "/images/original/missing.png"
Hi !
I still have some problems when attachments are videos.
In fact, the .exists? method return always false because the resource_type is not indicated.
Ex :
irb(main):004:0> Cloudinary::Uploader.exists? "overlay_91b5e610-2a89-0134-7dbc-0242ac110001.webm"
=> false
irb(main):005:0> Cloudinary::Uploader.exists? "overlay_91b5e610-2a89-0134-7dbc-0242ac110001.webm", {:resource_type=>:video}
=> true`
So @queued_for_delete is empty and nothing is deleting.
I get arround this issue by adding a method to determine resource_type by using the content_type and add resource_type to Cloudinary::Uploader.destroy command.
def resource_type
unless content_type.nil?
if content_type.include? "video"
log("resource_type - video")
return :video
else
log("resource_type - image")
return :image
end
end
end
But is not sufficient because paperclib set content_type to nil in queue_all_for_delete method.
So I had to also modify paperclip class.
Finally it's not really an issue but just some remarks to say video are not correctly manage by this gem (maybe in the roadmap ?).
I'am a new Ruby Developper so I don't have the best way to manage video ;)
Hi, I've just installed this gem, I think it's great but I have a problem.
I try to upload pdfs for my app through an api, I used paperclip on a local server and it worked perfectly but now with Heroku I need to use Cloudinary to handle the storage. My model file looks like this:
has_attached_file :pdf,
:storage => :cloudinary,
:cloudinary_resource_type => :pdf,
:folder => 'adjuntos/pdfs/:id/',
:path => 'adjuntos/pdfs/:id/:filename.:extension',
:url => '/:class/:id/:filename.:extension'
At first I had the Paperclip::Errors::InfiniteInterpolationError but I fixed it adding the path. Now I have the next error:
[fatal] CloudinaryException (public_id (adjuntos/pdfs/1/EV_IN_123456_CCC_8_#_11111_1.pdf) is invalid):
I already enabled the 'Auto-create folders' option in my settings but I'm getting the same error. I'm kind of new to this service and I don't know if this is a silly issue or is related to the gem.
Thanks in advance.
Hi !
I also have an issue with delete contents.
It seems path is not correct in flush_deletes.
I add this logs lines in the flush_deletes to see what's wrong :
def flush_deletes
log("deleting...")
@queued_for_delete.each do |path|
log("deleting #{path}")
::Cloudinary::Uploader.destroy path
end
@queued_for_delete.clear
end
And here are the logs, and file is not deleted :
[paperclip] deleting...
[paperclip] deleting avatar_96788ee0-1e8b-0134-7d9a-0242ac110001.png
When i tried with the rails Console, it work's fine if path is without extension :
โ rails console
Running via Spring preloader in process 906
Loading development environment (Rails 4.2.6)
irb(main):001:0> Cloudinary::Uploader.destroy('45d3b060-1e8a-0134-578f-525400c10e34.png')
=> {"result"=>"not found"}
irb(main):002:0> Cloudinary::Uploader.destroy('45d3b060-1e8a-0134-578f-525400c10e34')
=> {"result"=>"ok"}
Is this an issue or is it something wrong in my configuration ?
Thx.
Patrik
I got this problem when upload new images: public_id (/uploaded/images/images/53/original_14696773_1230106550395132_23944727_n) is invalid
. Here is my configuration:
has_attached_file :image, :storage => :cloudinary, path: "/uploaded/:class/:attachment/:id/:style_:filename", styles: { thumb: "300x200#", large: "1024x768>"}
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
Any problem with my path?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.