Forum: Ruby on Rails How might I use file_column for incoming email attachments?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Duane J. (Guest)
on 2006-01-01 00:27
(Received via mailing list)
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?

Thanks,

Duane J.
(canadaduane)
http://blog.inquirylabs.com/
Kyle M. (Guest)
on 2006-01-02 19:51
(Received via mailing list)
On 12/31/05, Duane J. <removed_email_address@domain.invalid> wrote:
>
> http://blog.inquirylabs.com/
>
>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

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
removed_email_address@domain.invalid
1-866-263-3261
Duane J. (Guest)
on 2006-01-03 05:48
(Received via mailing list)
On Jan 2, 2006, at 10:48 AM, Kyle M. wrote:

>> "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)?

Duane J.
(canadaduane)
http://blog.inquirylabs.com/
Kyle M. (Guest)
on 2006-01-03 20:16
(Received via mailing list)
On 1/2/06, Duane J. <removed_email_address@domain.invalid> wrote:
> >> However, I'm getting the following error from the ImageMagick
> >> Thanks,
> >>
> more of an "I don't quite understand how file_column automatically
> Duane J.
> (canadaduane)
> http://blog.inquirylabs.com/
>
>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

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
removed_email_address@domain.invalid
1-866-263-3261
Kyle M. (Guest)
on 2006-01-03 20:16
(Received via mailing list)
On 1/3/06, Kyle M. <removed_email_address@domain.invalid> wrote:
> > >>
> > >>
> > >> http://lists.rubyonrails.org/mailman/listinfo/rails
> > Thanks for looking in to this a bit, Kyle.  I think my question is
> >
>
>
> removed_email_address@domain.invalid
> 1-866-263-3261
>

Note that the solution I just proposed won't help with the RMagick
issue, just getting a TMail::Attachment into FileColumn

--
Kyle M.
Chief Technologist
E Factor Media // FN Interactive
removed_email_address@domain.invalid
1-866-263-3261
This topic is locked and can not be replied to.