Paperclip validation issue on production
Asked Answered
F

4

2

I have a Problem when I deploy my application on google cloud I get this error

has contents that are not what they are reported to be

Locally it works fine! I already tried to using the command_path. So I really don't know what I have to do next...

This is my model

has_mongoid_attached_file  :image,
    :styles => { :large => "380x380!" , :medium => "240x240", :small => "120x120!" },
    :storage => :fog,
    :fog_public => true,
    :fog_directory => 'XXXX',
    :path => "images/:id/:style/:basename.:extension",
    :fog_credentials => {  :provider => 'Google',
                           :google_storage_access_key_id => 'XXXXX',
                           :google_storage_secret_access_key => 'XXXXX'}

  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

Thank you for your efforts. I hope you guys can help me

Faggot answered 26/3, 2016 at 21:3 Comment(0)
F
6

Okay I found a result. I just created a initializers/paperclip.rb file

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end

Right now it work's perfectly for me.

If you have problems with ImageMagick on App Engine using Rails see this link

Faggot answered 27/3, 2016 at 23:38 Comment(1)
Do not know what its doing, But its working which matter and up voted your answer, can you please elaborate a little what its working onCowden
D
5

That issue occurs because the content-type discovered from file command returns empty string. Actually system is not able to find the file executable so a exception is raised and empty string is returned back. Check the code below

begin
    Paperclip.run("file", "-b --mime :file", :file => '/tmp/RackMultipart20160826-15649-kwvnq2.png').split(/[:;]\s+/).first
rescue Cocaine::CommandLineError
    ""
end

Solution:-

Add below line in you initializer file.

Paperclip.options[:command_path] = '/usr/bin'
Dextrogyrate answered 26/8, 2016 at 19:25 Comment(7)
Which initializer file?Faggot
You can put a new initializer file, by name paperclip.rb, actually adding it to any of the existing initializer file should work.Dextrogyrate
Do I have to remove the MediaTypeSpoofDetector? And do use as well Google App Engine and rails?Faggot
Yes remove it and try this solution, do up vote my answer if it solves your problem.Dextrogyrate
@Faggot /usr/bin this path may vary on your system, so just verify it once by running the following command in the terminal, which file the path which it returns must be added to Paperclip.options[:command_path].Dextrogyrate
Still not working the problem is using app engine I don't have access to more informationFaggot
In my case (docker ruby:alpine image) paperclip could not find the file executable but because it not installed on alpine by default. Huge thanks @NitinSatishSalunkeHeterogony
P
1

I know I am late to the party, but in working with a legacy RoR system, I ran into this issue. The problem arose in setting the app up in Docker. Ultimately paperclip calling imagemagick was attempting to use file to identify mime-type and the minimal Docker did not have it installed. apt-get install file fixed it.

Ploce answered 18/10, 2022 at 17:55 Comment(0)
D
0

Looks like Google Cloud can't determine MIME type of uploaded files.

You can map file extensions to types in you initializer (application.rb, production.rb or create initializers/paperclip.rb)

Paperclip.options[:content_type_mappings] = {
  :jpg => "image/jpeg",
  :png => "image/png",
  :gif => "image/gif"
}

But this way spoofing check won't be performed for image files.

Dahle answered 26/3, 2016 at 22:7 Comment(1)
Don't work for me I can upload the images to google cloud but only if my server running locally. I get this issue only when I deploy it remotely :/Faggot

© 2022 - 2024 — McMap. All rights reserved.