I’m writing a ‘Mailman’ model that catches emails sent to my
application (kind of like backpack, I think). The trouble is that
I’d like to save image attachments in the same was that file_column
saves them–in fact, I’d really like to use a simple assignment like
photo.image = attachment to save the image in its proper place.
However, I’m getting the following error from the ImageMagick
extension of file_column:
“Image invalid image”
(“image” is the name of the column, so that’s why it seems to be
duplicated).
Does anyone know how to leverage file_column’s fantastic simplicity
when dealing with this kind of incoming attachment?
In grepping the source, the only place “invalid image” occurs is when
RMagick throws an exception. I use a modified magick_file_column.rb
that uses the command-line Imagemagick, because I’m not a fan of
RMagick, so I can’t say too much, but try breakpointing the first few
lines of the magick_file_column.rb to see what that exception is
coming from.
–
Kyle M.
Chief Technologist
E Factor Media // FN Interactive [email protected]
1-866-263-3261
“Image invalid image”
(canadaduane)
RMagick throws an exception. I use a modified magick_file_column.rb
that uses the command-line Imagemagick, because I’m not a fan of
RMagick, so I can’t say too much, but try breakpointing the first few
lines of the magick_file_column.rb to see what that exception is
coming from.
Thanks for looking in to this a bit, Kyle. I think my question is
more of an “I don’t quite understand how file_column automatically
handles IOString objects, why won’t it handle a TMail::Attachment
object?” I did find the error message that you pointed out, but I
was a bit surprised at the size of the plugin as a whole. Quite an
achievement!
Any idea how I might trick or otherwise modify file_column in to
accepting TMail::Attachment object assignment (e.g. I’d like to do
this: User.new(:photo => attachment) where :photo is a file_column
column and attachment is a TMail::Attachment object)?
File_column relies on receiving a CGI-uploaded file, which is either a
File, or an IOString object, depending on filesize, which has been
extended with a few extra methods (original_filename, size,
local_path, content_type). If you pass an ordinary File,
FileColumn::FileCompat is mixed in to provide this functionality.
This happens in BaseUploadedFile.assign().
I don’t know much about TMail::Attachment, but if its similar enough
to File, you could replace the first line in
BaseUploadedFile.assign():
#old
if file.is_a? File
#new
if file.is_a?(File) || file.is_a?(TMail::Attachment)
–
Kyle M.
Chief Technologist
E Factor Media // FN Interactive [email protected]
1-866-263-3261
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.