Reputation: 683
I am getting an error when trying to upload images to my (listings) using the paperclip gem. The error that the browser outputs is: 1 error prohibited this listing from being saved: Image has contents that are not what they are reported to be **As a note, image magic has been successfully installed on my computer and there are no issues there
my listing.rb file
class Listing < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
my gemfile
gem "paperclip", "~> 4.3"
my listings_controller
def listing_params
params.require(:listing).permit(:name, :description, :price, :image)
end
end
and finally my form
<%= form_for @listing, :html => { :multipart => true } do |f| %>
...
...
<div class="form-group">
<%= f.file_field :image, class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
Upvotes: 1
Views: 221
Reputation: 76784
It sounds like you need to include file
on your system.
If you're using Windows, you need to download file from this URL, install it on your hard drive and then add it to your PATH environment var:
- Click "Start"
- On "Computer", right-click and select "Properties"
- In Properties, select "Advanced System Settings"
- Click the "Environment Variables" button
- Locate the "PATH" var - at the end, add the path to your newly installed
file.exe
(typicallyC:\Program Files (x86)\GnuWin32\bin
)- Restart any CMD shells you have open & see if it works
Upvotes: 2
Reputation: 9226
You're probably trying to attach a file that is not properly recognised as an image, or one that has an image extension and has different content (like a PDF, for example).
Some workarounds are discussed here: https://github.com/thoughtbot/paperclip/issues/1924
It might help to check the log file as well - it should tell you what Paperclip thinks the type of the attachment is.
Upvotes: 0