westman2222
westman2222

Reputation: 683

error uploading images using paperclip (local server)

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

Answers (2)

Richard Peck
Richard Peck

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:

  1. Click "Start"
  2. On "Computer", right-click and select "Properties"
  3. In Properties, select "Advanced System Settings"
  4. Click the "Environment Variables" button
  5. Locate the "PATH" var - at the end, add the path to your newly installed file.exe (typically C:\Program Files (x86)\GnuWin32\bin)
  6. Restart any CMD shells you have open & see if it works

Upvotes: 2

eugen
eugen

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

Related Questions