Paper clip file upload issue in windows 10 - ruby-on-rails

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

Related

Paperclip error while trying to upload a file (windows)

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

why font list is empty for imagemagick?

I am trying to use ImageMagick to add some text to an image. But I found it always said that my specified font doesn't exist. After reading the manual carefully I noticed that I can use convert -list font to output all the available fonts, but after trying I figured out that the list of available font is empty.
This is what I get:
shell$ convert -list font
shell$
Thanks for any kind of tips.
I just managed to tell ImageMagick about the fonts on my OSX system like this:
# Make a new directory for ImageMagick local settings and cd into it
mkdir ~/.magick
cd ~/.magick
# Grab script to find all fonts on system and store them in a config file
curl -L http://www.imagemagick.org/Usage/scripts/imagick_type_gen > type_gen
# Run script, telling it where my fonts are and create "type.xml" file with list
find /System/Library/Fonts /Library/Fonts ~/Library/Fonts -name "*.[to]tf" | perl type_gen -f - > type.xml
# Go to ImageMagick config folder - see note at end to find correct folder
cd /usr/local/Cellar/imagemagick/6.8.9-1/etc/ImageMagick-6
# Edit system config file called "type.xml" and add line near end to tell IM to look at local file we made in earlier step
<typemap>
<include file="type-ghostscript.xml" />
<include file="~/.magick/type.xml" /> ### THIS LINE ADDED ###
</typemap>
How to find the correct folder for your type.xml file
The folder where type.xml is stored can vary enormously between systems and versions. Most recently the user configuration folder seems to be ~/.config/ImageMagick, but the best way I know of finding it is to run the following command to see where ImageMagick is looking:
convert -debug configure -list font 2>&1 | grep -E "Searching|Loading"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/share/ImageMagick-7/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/lib/ImageMagick//config-Q16HDRI/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type.xml"
Searching for configure file: "/usr/local/Cellar/imagemagick/7.0.11-6/share/doc/ImageMagick-7/type.xml"
Searching for configure file: "/Users/username/.config/ImageMagick/type.xml"
Loading type configure file "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type.xml" ...
Loading type configure file "/usr/local/Cellar/imagemagick/7.0.11-6/etc/ImageMagick-7/type-ghostscript.xml" ...
Loading type configure file "/Users/username/.config/ImageMagick/type.xml" ...
So there are lots of places you could insert the fonts. In general, if you choose a folder starting with /etc or /usr/local the fonts will be available for all users and for scripts in your web server to use - if you want that. On the other hand, if you are just a single user, you may prefer to keep the font config file in your login directory, e.g. ~/.config/ImageMagick/type.xml.
With ImageMagic 7.0.10 on MacOs Catalina I have done the following which did the trick.
Edited /usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type.xml and replaced type-ghostscript with type-apple
Edited /usr/local/Cellar/imagemagick/7.0.10-7/etc/ImageMagick-7/type-apple.xml and added "/System/Library/Fonts/Supplemental" in front of all glyph paths

CarrierWave MiniMagick resizing gives an error

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

Rails 2 + Paperclip + ImageMagick in Linux is not working?

I set up a app in windows using paperclip and imagemagick and it works fine.
Now, I had to migrate this APP to linux.
I already have paperclip's gem and imagemagick but I can't make it work.
I keep getting this message when saving the image:
sh: identify: command not found
Why? Am I missing something?
Thank you!
ps: I'm able to run the "identify" command from my app's directory.
Within your config/environments/development.rb file (or production if necessary) you can add Paperclips command_path option:
Paperclip.options[:command_path] = '/opt/local/bin'
You will want to replace /opt/local/bin with the directory path returned typing in your command line:
$ which identify

Paperclip / Passenger NotIdentifiedByImageMagickError:

When I try to upload a photo in Ruby on Rails using Paperclip on my local machine it works perfectly.
When I try to upload a photo in Ruby on Rails using Paperclip on our Linux (CentOS 5.2) server with Apache and Phusion Passenger, I get:
2 errors prohibited this user from being saved
There were problems with the following fields:
- Avatar /tmp/stream20091026-21120-1qdbnul-0 is not recognized by the 'identify' command.
- Avatar /tmp/stream20091026-21120-1qdbnul-0 is not recognized by the 'identify' command.
I tried adding:
Paperclip.options[:command_path] = "/usr/local/bin"
to production.rb but it didn't make a difference.
In the log files I get the following errors:
Parameters: {"commit"=>"Upload",
"action"=>"update", "_method"=>"put",
"authenticity_token"=>"419410afc22737cd2f6b6096a95327db76a48ba9",
"controller"=>"users",
"user"=>{"avatar"=>#}}
[paperclip] Saving attachments.
[paperclip] An error was received
while processing:
/tmp/stream20091026-20752-1g568yk-0 is
not recognized by the 'identify'
command.
Identify is a command-line utility inside the ImageMagick package.
From its homepage:
The identify program describes the
format and characteristics of one or
more image files. It also reports if
an image is incomplete or corrupt. The
information returned includes the
image number, the file name, the width
and height of the image, whether the
image is colormapped or not, the
number of colors in the image, the
number of bytes in the image, the
format of the image (JPEG, PNM, etc.),
and finally the number of seconds it
took to read and process the image.
Many more attributes are available
with the verbose option.
First, copy the image on the server and run the identify command on it. You should receive something like:
identify ~/capture.jpg
capture.jpg JPEG 1216x244 1216x244+0+0 8-bit DirectClass 97.7kb
If you receive an error, try upgrading the ImageMagick package on your server. You may find an updated binary release here:
http://www.imagemagick.org/script/binary-releases.php
in my case with same error, reinstalling imagemagic helped out (ubuntu 12.10)

Resources