i´m getting this error when editing a model specifically when i delete an image associated to it and I select another:
Paperclip::NotIdentifiedByImageMagickError in Admin/packsController#update
Chrysanthemumprueba4.jpg is not recognized by the 'identify' command.
C:/Users/.../vendor/plugins/thoughtbot-paperclip-fc792c8/lib/paperclip/geometry.rb:24:in `from_file'
But when i create a new pack and I select images for it, it works ok.
I have two tables: packs and pack_images,and pack_images has the photos for the pack associated, here are the relations:
class Pack < ActiveRecord::Base
has_many :pack_images, :dependent => :destroy
end
class PackImage < ActiveRecord::Base
belongs_to :pack
attr_accessor :height, :width
has_attached_file :photo, :url => "/:attachment/:class/:id/:style_:basename.:extension", :styles => {:principal => "240x240>", :original => "400x400>", ...}
end
This is the controller's action that throws me the error:
def update
#pack = Pack.find(params[:id])
#pack.pack_products
unless params[:pack][:pack_images_attributes].nil?
params[:pack][:pack_images_attributes].count.times do |i|
unless params[:pack][:pack_images_attributes][:"#{i.to_s}"][:photo].blank?
file = params[:pack][:pack_images_attributes][:"#{i.to_s}"][:photo]
dimensions = Paperclip::Geometry.from_file(file)
#pack.pack_images[i].width = dimensions.width
#pack.pack_images[i].height = dimensions.height
end
end
end
respond_to do |format|
#pack.update_attributes(params[:pack])
format.html { redirect_to(admin_pack_path(#pack.id), :notice => 'Pack updated') }
end
I noticed that, when updating I get less parameters (only the photo's name) than when creating (photo's name,file type,width,height,etc).
I hope you can help me
Thank you very much
it used to work fine for pdf and images, tried out for an hour or so, followed everything I googled later the problem was found in my model has_attached_file :attachment,
:styles => {:original=> "125x125#"}
had to comment this line, and it worked for other attachments like docx or odt etc..
so in your case :styles => {:principal => "240x240>", :original => "400x400>"}
check out and comment.
Locate the path of the identify command like this:
$ which identify
For me the above command prints this: /usr/local/bin/identify
Add this in some initializer file:
Paperclip::Attachment.default_options[:command_path] = "/usr/local/bin"
One reason this error occurs is when you try to determine the dimensions of an image that does not exist:
Paperclip::Geometry.from_file(nil)
This command will hang and cause this error.
Try to run the "identify" command from ImageMagick on this image. It seems something with your ImageMagick install.
I had the exact same issue. Windows 8 64bit, Rails 4, ImageMagick-6.8.7-1-Q16-x64-static.exe. Do this :
In the root of your rails app (from Git Bash)
$ which identify
/c/Program Files/ImageMagick-6.8.7-Q16/./identify
Then
$ cd "/c/Program Files/ImageMagick-6.8.7-Q16"
Don't forget the quotes. Copy all executables to you /bin directory. I actually copied all these files to be certain.
$ cp * /bin
And voila paperclip works!
Related
I've been searching around for a while now but can't seem to find the answer.
I'm using paperclip and postgresql database to upload and store files.
The error I am getting is :
Errno::EACCES in DocumentsController#create
Permission denied # dir_s_mkdir - /documents
And the error code is specifically referring to this section in the documents controller:
def create
#document = current_user.documents.build(documents_params)
if #document.save
redirect_to #document
else
render 'new'
end
end
I recently switched my database from sqlite to postgresql and it is working perfectly fine online (I have uploaded it with heroku), just not in development.
Also, I am able to edit and update documents that have been uploaded already in development, just not able to upload any.
Are there any config files or something that I need to modify to grand permission for # dir_s_mkdir?
Finally I managed to fix this problem.
Because I had modified my database to use PostgreSQL with Heroku I needed to also modify my Document model, to accomodate for both production and development environments.
I also had to change the :url that the document object was assigning to in development. The updated :url became:
:url => "/system/documents/pdfs/:id/:basename.:extension"
Below is the updated document.rb model (for the paperclip section):
if Rails.env.development?
has_attached_file :pdf, :use_timestamp => false,
:url => "/system/documents/pdfs/:id/:basename.:extension",
:path => ":rails_root/public/system/documents/pdfs/:id/:basename.:extension"
validates_attachment_content_type :pdf, :content_type => ["application/pdf","application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"]
else
has_attached_file :pdf, :use_timestamp => false
validates_attachment_content_type :pdf, :content_type => ["application/pdf","application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"]
end
Many answers I referred to were saying to use either:
sudo chown -R username app_path
/* or */
chmod -R 777 PATH_TO_APP/uploads
/* or */
chmod -R 777 PATH_TO_APP/tmp
Although changing ownership of a file/folder is not a good option, as it sets every file as executable, readable, and writeable by anyone.
1 error prohibited this listing from being saved:
Image has contents that are not what they are reported to be
That's the error that I get when I try to upload a picture for a listing. I've tried various types of validations and nothing is working.
This is what my Model looks like.
class Listing < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "200x", :thumb =>"100x100>" }, :default_url => "default.jpg"
validates_attachment :image, content_type: { content_type: /\Aimage\/.*\Z/ }
end
Can someone please explain to me what I did wrong, and what I can do to fix it. I really want to keep working on this application but I've hit a problem!
You need to change the following
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
Also make sure that you are indeed uploading images with the mentioned extensions
It may be caused because you don't have file program (probably you don't use Unix system?)
file is used by paperclip to check whether sent file is what it should be or not (based on your validator).
If you are on Windows, you should manually download and install file for Windows and add it to either
Windows PATH environment variable,
project environments (config/environments/development.rb, add line Paperclip.options[:command_path] = '{your_path_to_dir_with_file/bin}' )
After that, restart console, server and it should work.
This is what you can do only for windows :
Install the exe by
download the exe from this link file.exe
test if is well installed by running your cmd and put the following instructions convert logo: logo.miff then run ' imdisplay logo.miff '
you will get custom logo image,that will pop up on your windows screen.
From here now you can start configuring everything on rails app
Open config/environments/development.rb
Add the following line: Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'
If your rails server is currently running,brake the server and then run again rails s.After that you should be ready to go.Upload image on your app
I having a big issue here. I really tried, but I can't solve this problem by myself, so I hope people can help me here.
Before talk about my problem, I must say I'm using Paperclip and IMGKit in my Project, but I think the problem is with Paperclip.
I create a Rails Task to take snapshots from the home page of some sites. Sometime ago everything is working fine, but now everything goes down. I import my real database from Heroku to localhost (without any images and migrations of paperclip), run the migrations, delete all old files from 'public/system' and run my task again (to take snapshot of all websites).
So, now I have:
The paths and original images are generated, but when I try to load them in View, this just show as a broken image.
Paperclip doesn't generate the path and converted images of :styles.
Sites that don't have image, I can see my default image correctly.
ImageMagick seems to be working, I try convert some images and worked like a charm.
Let's take a look at the code. Assume that I'm running a task that will perform this task to all sites in my database. The sites are called "items" in my architecture.
Development.rb
#config/environments/development.rb
# "which convert" give me this path
Paperclip.options[:command_path] = "/usr/local/bin/"
Item.rb (model)
My task just call "object.save" of every site in the DB, so my code starts on before_save.
has_attached_file :image,
:styles => { :small => "200x147#" },
:convert_options => { :small => "-quality 75 -strip" },
:default_url => '/images/:style/bitcoin-earth.jpg'
before_save :generate_data
def generate_data
self.image = get_image(self.id, self.url_original)
end
# Take snapshot of the website
def get_image(filename, link)
kit = IMGKit.new(link.to_s, :quality => 100, :width => 1024, :height => 768)
file = Tempfile.new(["template_#{filename}", 'png'], 'tmp',
:encoding => 'ascii-8bit')
file.write(kit.to_img(:png))
file.flush
return file
end
View
<%= image_tag store.image.url %>
Gemfile
gem "paperclip"
If I try to run rake paperclip:refresh:missing_styles, the task finish very fast without any error. But if I try to run rake paperclip:refresh CLASS=Item I got:
Image Paperclip::Errors::NotIdentifiedByImageMagickError
And yes, I already search for it and I didn't found a solution for my case.
A little tip?
When I "inspect element" in my project and try to see the source of the item image, I saw:
http://localhost:3000/public/system/items/images/000/000/216/original/template_21620140109-14507-1c0yszzpng?1389305824
But if I go to my project folder, I just see a image called template_21620140109-21209-1yls03opng. Note that doesn't exist any "?1389305824" there. See the image above.
Well, I think that's it. What can be the problem? I really need solve this issue, please, help me :/
[ Edited on Jan 10, 2013 ]
Item.rb (model):
before_save :generate_data
def generate_data
file = File.open(get_image(self.id, self.url_original))
self.image = file
file.close
end
def get_image(filename, link)
kit = IMGKit.new(link.to_s, :quality => 100,
:width => 1024, :height => 768)
file = Tempfile.new(["template_#{filename}", '.png'], 'tmp',
:encoding => 'ascii-8bit')
file.write(kit.to_img(:png))
file.flush
return file
end
Now I don't have any error on console while getting images and saving on DB, but Paperclip still don't generate my :styles. When I go to log/development.log, I can see this error, but I don't know what I can do to solve:
Command :: file -b --mime 'tmp/template_24320140110-17577-80zj1c.png'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/template_24320140110-17577-80zj1c20140110-17577-mqa2q3.png[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I think we're getting closer, please, keep helping me :)
I think your problem is here:
template_21620140109-14507-1c0yszzpng?1389305824 #-> should have .png (not a valid image)
Image
This might not be the problem, but maybe you could streamline your method to exclude the temporary file:
# Take snapshot of the website
def get_image(filename, link)
kit = IMGKit.new(link.to_s, :quality => 100, :width => 1024, :height => 768)
file = kit.to_file("system/temp/template_#{filename}")
return file
end
I think the issue is that ImageMagick is not being passed a "real" file, and consequently you're getting the unrecognized image issues
I am using ck editor in rails having database mongo db. I followed the link https://github.com/galetahub/ckeditor . I am succes in doing work with the help of ckeditor.
since my view.html.erb code is like this
<%= f.cktext_area :description, :toolbar => 'Easy', :width => 800, :height => 200 %><br>
and my show page is
<%= raw#department.description %>
it does not works for file cases.
I have my model attachment_file.rb is
class Ckeditor::AttachmentFile < Ckeditor::Asset
has_mongoid_attached_file :data,
:url => "/ckeditor_assets/attachments/:id/:filename",
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
validates_attachment_size :data, :less_than => 100.megabytes
validates_attachment_presence :data
def url_thumb
#url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
It is working for image cases but not working for zip file or any attachement. when it comes to the file cases it can upload file successfully with its path. but to download that file by user it doesnot work. I mean backend works properly for all features. But lacks to download that uploaded file stops by
`javascript:void(0)/*130*/
i have found the answer of this problem . First run this in terminal.
$ sudo chmod -R 777 /usr/share/ruby-rvm/gems/ruby-1.9.3-p194/gems/ckeditor-3.7.1
follow this path in your computer since i am using linux and my gem file locates here.
/usr/share/ruby-rvm/gems/ruby-1.9.3-p194/gems/ckeditor-3.7.1/vendor/assets/javascripts/ckeditor/plugins/attachment/dialogs
and open attachement.js file and edit it with the code that u find from tha above link.
click
Now ck editor will works for file attachment also.
Seem like you encounter this bug in CKeditor:
It sugests adding before filter as fix eg:
# app/model/department.rb
before_save :fix_ckeditor_attachment_paths
def fix_ckeditor_attachment_paths
if self.description.index(/_cke_saved_href/)
self.description = self.body.gsub(/_cke_saved_href/, 'href')
end
end
A few system details:
Mac OS X Lion 10.7.2, Rails 3, Paperclip gem.
ImageMagick 6.7.3-0, binaries installed using MacPorts in /opt/local/bin.
Using WEBrick in development environment.
I'm trying to upload photos that should get resized down into thumbnails. When I do so, the original uploaded file is saved and can be accessed via HTTP correctly. When I try to accessed the thumbnail version, I get this error:
Routing Error
No route matches "[file_URL]"
Before that, when uploading a valid PNG file, I see this error in my WEBrick log:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /var/folders/n4/62q22gb52rjd0h13cx_j8vv40000gq/T/stream20111020-24984-17560xt-0.png is not recognized by the 'identify' command.>
Doing which identify outputs:
/opt/local/bin/identify
Calling identify with the path of the uploaded file correctly identifies the file as a PNG file.
I confirmed rails server starts the development environment. I added the following in config/environments/development.rb:
Paperclip.options[:command_path] = "/opt/local/bin"
My Photo model has the following:
class Photo < ActiveRecord::Base
has_attached_file :file, :default_style => :view, :styles => {
:view => { :geometry => '520x390>', :format => 'jpg' },
:preview => { :geometry => '160x120>', :format => 'jpg' } }
validates_attachment_content_type :file,
:content_type => [ 'image/jpeg', 'image/pjpeg', 'image/png' ]
end
My Photos controller:
class PhotosController < ApplicationController
# ...
def create
#photo = Photo.create params[:photo]
end
end
Like I said, I can access the original images in the URL path system/files/:id/original, but the resized versions I want aren't accessible and are not found in the filesystem. WEBrick's log suggest Paperclip can't even have ImageMagick identify the images before resizing them.
Any ideas? Thanks in advance!
This may be a duplicate question, as stated above, but this problem was caused by a recent bug in ImageMagick 6.7.3-0 fixed soon after in 6.7.3-1. MacPorts has also been updated with the new release.
In 6.7.3-0, stating the frame number in the file path (e.g. identify /path/to/file.png[0]) caused ImageMagick to segfault ("Segmentation fault 11"). Paperclip specified the frame number to ensure its processing the first frame or page of an image file.
The new release of ImageMagick solved this problem. The bug was mentioned on MacPorts:
https://trac.macports.org/ticket/31643