I'm using Rails 3 with Paperclip + Rails:
Gemfile
gem "paperclip"
gem "mongoid-paperclip", require: 'mongoid_paperclip'
Everything works fine unless a user uploads a photo with a filename with non-alphanumeric characters like so:
thing 1/2/3/.PNG
I've tried handling this with before_post_process
before_validation
:
def strip_strange_characters_from_attachments
# Set the clean Attachment File Title
self.attachment.instance.meta['file_name'] = "test.png"
end
However Rails is erring beforehand and files are not uploading. Error below. Any ideas?
[2014-06-10 13:54:47] INFO Command :: identify -format %wx%h '/var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG[0]'
[2014-06-10 13:54:47] INFO [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG is not recognized by the 'identify' command.>
[2014-06-10 13:54:47] INFO Command :: identify -format %wx%h '/var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG[0]'
[2014-06-10 13:54:47] INFO [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG is not recognized by the 'identify' command.>
[2014-06-10 13:54:47] INFO Command :: identify -format %wx%h '/var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG[0]'
[2014-06-10 13:54:47] INFO Completed 422 Unprocessable Entity in 120.0ms
[2014-06-10 13:54:48] INFO Mongo: (1.5333ms) | Query count: 3
[2014-06-10 13:54:48] FATAL
Mongoid::Errors::Validations -
Problem:
Validation of Mongo::Attachment failed.
Summary:
The following errors were found: Attachment /var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG is not recognized by the 'identify' command., Attachment /var/folders/g_/kythn1dx4fbbry5npb4jx1cr0000gn/T/thing 1:2:3:20140610-41978-ksy5e9.PNG is not recognized by the 'identify' command.
Resolution:
Any ideas / suggestions on handling this error?