I am new to rails and I am trying to upload a file using the Paperclip Gem but I am facing the following error. (Note I am using windows so it might be a problem with some file commands).
Note I did install GnuWin31 and added the path C:\Program Files
(x86)\GnuWin32\bin
enter image description here
Related
I got an issue when I tried to upload an image using the paperclip gem.
It is working fine on my ubuntu system but not on windows 10.
Rails version = 5.1.2 Ruby version = 2.2.6p396 paperclip = 5.2.1
[paperclip] Trying to link C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1yxm99j.png to C
:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png
[paperclip] Link failed with File exists # sys_fail2 - C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20
180310-5860-1mjjyje.png; copying link C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1yxm9
9j.png to C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png
Command :: file -b --mime "C:/Users/.../Temp/c935d187f0b998ef720390f85014ed1e20180310-5860-1mjjyje.png"
[paperclip] Content Type Spoof: Filename Dog.png (image/png from Headers, ["image/png"] from Extension), content type discovered from file command: . See documentation to allow this combination.
Thanks in advance.
As you can see here:
[paperclip] Content Type Spoof: Filename Dog.png (image/png from Headers, ["image/png"] from Extension), content type discovered from file command: . See documentation to allow this combination.
Paperclip (or more precisely file -b --mime command used to identify Content-Type) silently fails leaving you with empty string as a result.
It's working fine on Ubuntu because file program is included in your distribution (you can verify that by using commands like man file or which file). If you run sudo apt remove file on Ubuntu and then try to upload file it will result in error message same as above.
If you want to use Paperclip on Windows, according to this section, you should install file manually and add path to your environment variable:
Download & install file from this URL
Go to GnuWin32 directory and run file.exe to test it works.
Add file.exe path to your PATH variable or add Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin to your config/environments
I try to upload a product image to my Spree app, but i get this error
5errors prohibited this record from being saved:
Attachment Paperclip returned errors for file 'index.jpg' - check ImageMagick installation or image source file.
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Attachment Paperclip::Errors::NotIdentifiedByImageMagickError
Should i install a gem, relocate my src image? Whats the problem here
You should to install ImageMagick. Follow these steps for install on Windows:
Download ImageMagick (you need to choose static version for your 32/64 bit OS)
Checked Add application directory to your system path and install
Reopen your command prompt to reload your PATH variables
Run convert -v to check the install worked
Okay so the problem is pretty complicated and after trying to solve it for about 3 hours i finally got it.
First, you have to remove the convert.exe from your System32 files.
We do this, because the Spree app relies on legacy code and when it
tries to upload the image the default convert.exe starts, we don't
want that.
Second you download and install the dynamic installation from the imagemagick site and you have to be sure to check the legacy support so the convert command gets supported.
I dont know if you have to, but i installed the paperclip gem. You may have to do that for it to work.
The whole reason this bug happens, is because Windows. So if you are new to this party, dual boot your station or swap to Ubuntu/Mac whatever. Seriously though, when the app tries to upload it uses the convert command, but convert is already a default Windows command so you can't upload the picture properly. So we disable the command and then we replace it with our imagemagick installation. That's it.Also good luck trying to delete the convert.exe from system32, its a weird process, but you can solve it with some google-fu.
Thanks to Michael for pointing me to right way.
I am running this code in my model on an after_update call:
require 'rmagick'
file = photo.url(:thumb) #created by paperclip
img = Magick::Image.read(file).first
and I get unable to open file `/assets/contacts/1/thumb/image.png' though that file is there and is used throughout the rest of the app, so I don't suspect permissions as an issue. Rails is looking at my assets directory for everything else, and I can access the image via direct URL on my local box, so I know it exists. I do have ImageMagick installed via homebrew, and I ran "identify -list format" and the formats seem to be installed too. I have added it to the gemfile and run bundle install as well. What other things could I try to troubleshoot this?
How do I know what directory RMagick thinks is root, or is there some other reason why I can't read the file? I have read all I can find on Google, forums, Stack, IRC, and no one seems to have an answer.
Paperclip gem stores uploaded images in public folder. So, if your image path inside public folder is:
contacts --> 1 --> thumb --> image.png
Than, you should use path '/contacts/1/thumb/image.png' . Because, if there is no forward slash in URL than rails will by default search inside the assets folder for images.
I just followed every step for installing ruby on rails as it says here http://rubyonrails.org/download but i can't create succesfully a rails project. This is exactly what I did:
Installed ruby with windows installer v2.0.0-p0 x64 (I'm running W8 pro)
Installed RubyGems with the following procedure:
Downloaded thee .zip file from the webpage
Unzipped the folder into the Ruby200-x64 folder in C:
Excecuted the "setup.rb" file
Installed Rails with the following procedure:
Opened a CMD and put gem install rails
But when I try to "create the application skeleton" through the command
rails new C:\Users\Andrés\Desktop\Mediplan
I get the following:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/generators/app_base-rb:100:in 'expand_path' : incompatible character encodings: CP850 and UTF-8 <Encoding::CompatibilityError>
Anybody knows a fix for this?
(Let me know if additional information is needed)
Could be due to the é in Andrés. Try changing your path to the Desktop first, then create the Rails app. Try this:
cd C:\Users\Andrés\Desktop
rails new Mediplan
I am using CarrierWave with MiniMagick to resize and uploaded file. I have the version directive in my uploader
version :thumb do
process :resize_to_limit => [100, 100]
end
But when I upload the file, the operation fails. The exception I am getting is
No such file or directory - identify -ping /var/folders/Au/AuBTXIH8HzCAhKdy0jvi+k+++TI/-Tmp-/mini_magick20120906-64039-1gx1ptu.jpg
The name of the file I am uploading is hat.jpg. The /var/folders/Au/AuBTXIH8HzCAhKdy0jvi+k+++TI/-Tmp-/ directory does exist, but when I do the upload I do not see the file in question being created.
Any suggestions as to what the problem may be?
Edit: I have found that the specific issue is that MiniMagick is spawning a command to run identify, and the identify command is not being found. But it is on my system at /usr/local/bin/identify --it was installed as part of ImageMagick.For some reason MiniMagick is not picking it up.
Discovered that the problem was with my RubyMine IDE, not my application or ImageMagick or MiniMagick.
It seems when the RubyMine IDE is launched (by double-clicking the RubyMine icon) it does not inherit the PATH that would exist for a terminal session. Therefore /usr/local/bin/ was not in my server path when I launched the rails server from within RubyMine.
I am able to run my application successfully when launching the server from the command line. I also found that if I launch RubyMine from the command line (using open -a RubyMine), then the terminal session is inherited and everything works as expected.
add to the TOP of your /etc/paths:
/usr/local/bin/
This will tell the mac OS that new shells should have this variable.
I say to add to the top because with homebrew, you are often adding paths that override built in mac applications