Paperclip File Not Found Error
Ok I managed to solve it.
It was a problem with Cocaine. Seems paperclip has a dependency on cocaine that only says it must be Cociane > 0.02. The latest version of Cocaine 0.4.2 (at the time of this writing) has a new API which is not backward compatible. You need to downgrade to Cocaine 0.3.2.
Simply put this in your Gemfile before paperclip:
gem "cocaine", "0.3.2"
Paperclip Error
The Paperclip.options[:command_path] setting is for the location of your ImageMagick executables (in this case identify). Try running which identify
and setting the option to be the directory that is returned. If that command doesn't return anything, make sure that ImageMagick is properly installed.
Rails Paper Clip upload not working... No error thrown, rolls back transaction
For some reason, I was able to fix this issue in the most peculiar way possible. I UNINSTALLED ImageMagick, a dependency of Paperclip, and suddenly everything worked?? I absolutely cannot explain why, but hey, it worked...
Obviously not the best answer as to why this was happening, but at least I can move on now. I hope the issue does not appear again when moving to production.
Paperclip Error: NotIdentifiedByImageMagickError
Most likely this is caused by the API change in Cocaine 4 which Paperclip has not caught up to yet. Try using the earlier version of Cocaine by inserting this line into your Gemfile:
gem "cocaine", "= 0.3.2"
Paperclip upload and showing the image not working
The problem is the way you're trying to use the styles option, it must be styles
, replace it and try again:
class Recipe < ApplicationRecord
has_attached_file :image, styles: { medium: '400x400#' }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
This makes Paperclip only execute the commands:
Command :: file -b --mime
to start the transactionCommand :: file -b --mime
to create a copy
instead:
Command :: file -b --mime
Command :: identify -format
Command :: identify -format %m
Command :: convert
Command :: file -b --mime
Hence you can't get the image by the :medium
style, but you can access its url and show it through an image tag, but styles won't work.
Paperclip type validation always giving error
I went into the same issue than you (even tried the other ways the thread suggests), and Rachel is right about the version. Paperclip 4 has some issue with spoofing. Changing it to 3.5 solved my problem.
Btw, if you still want to make it work, it seems to be the issue discussed here ( with a workaround given )
I can't seem to get pictures to upload with paperclip, I don't get an error after uploading
Paper clip for windows 7
If you're using Windows 7+
as a development environment, you may need to install the file.exe
application manually. The file spoofing system in Paperclip 4+ relies on this; if you don't have it working, you'll receive Validation failed: Upload file has an extension that does not match its contents. errors.
To manually install, you should perform the following:
Download & install file from this URL
To test, you can use the following: untitled
Paperclip is distributed as a gem, which is how it should be used in your app.
Next, you need to integrate with your environment - preferrably through the PATH variable, or by changing your config/environments/development.rb file
PATH
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
OR
Environment
1. Open `config/environments/development.rb`
2. Add the following line: `Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'`
3. Restart your Rails server
Either of these methods will give your Rails setup access to the file.exe functionality, this providing the ability to check the contents of a file (fixing the spoofing problem)
Include the gem in your Gemfile:
gem "paperclip", "~> 4.2"
In MODEL
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png", :path => ":rails_root/public/system/:class/:attachment/:id_partition/:style/:filename"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
Migration
class AddAvatarColumnsToUsers < ActiveRecord::Migration
def self.up
add_attachment :users, :avatar
end
def self.down
remove_attachment :users, :avatar
end
end
Views
<%= form_for @user, :url => users_path, :html => { :multipart => true } do |form| %>
<%= form.file_field :avatar %>
<% end %>
Controller
def create
@user = User.create( user_params )
end
private
# Use strong_parameters for attribute whitelisting
# Be sure to update your create() and update() controller methods.
def user_params
params.require(:user).permit(:avatar)
end
Show Views
<%= image_tag @user.avatar.url %>
<%= image_tag @user.avatar.url(:medium) %>
<%= image_tag @user.avatar.url(:thumb) %>
For FOG
config/environments/*.rb
files on config.paperclip_defaults
, these will get merged into Paperclip::Attachment.default_options
as your Rails app boots. An example:
module YourApp
class Application < Rails::Application
# Other code...
config.paperclip_defaults = {:storage => :fog, :fog_credentials => {:provider => "Local", :local_root => "#{Rails.root}/public"}, :fog_directory => "", :fog_host => "localhost"}
end
end
And it will work paper clip in win 7
Paperclip uploads 404ing
The behavior you describe it's a little weird. I suggest you set both :url and :path in a way similar to this:
url: '/:class/:id/:style.:extension',
path: ':rails_root/public:url'
This means images will be stored in:
"#{Rails.root}/public/bookmarks/:id/:style.:extension"
And the URL will give you something like:
/bookmarks/bookmarks/1/thumbs.png
Note that you can do this using config.paperclip_defaults
in "application.rb", so you don't have to do it on each model. And you can override this on "production.rb" if you want a different path or storage, e.g.:
config.paperclip_defaults = config.paperclip_defaults.merge({
storage: :s3,
path: 'project_name/public:url'
})
Related Topics
Documentation for Psych To_Yaml Options
Clicking a Button with Ruby Mechanize
How to Disable All Form_For Input Fields in Ruby on Rails App
Generate a Nested JSON Array in Jbuilder
Clicking Link with JavaScript in Mechanize
How to Modify a Text File in Ruby
Automatic Associations in Ruby on Rails Fixtures
Undefined Method Pluralize for Main:Object
Is Subclassing a User Model Really Bad to Do in Rails
How to Find All Modules and Classes Within a Module, Recursively
Ruby: Yield Block from a Block
Save Image with Mechanize and Nokogiri
How to Share State Between Scenarios Using Cucumber
Generate Array of Numbers That Fit to a Probability Distribution in Ruby
Shorter Way to Pass Every Element of an Array to a Function
How to Best Handle Per-Model Database Connections with Activerecord