Forum: Ruby on Rails Using image_tag and send_data

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.
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 15:33
(Received via mailing list)
I am using image_tag to load an image that I've saved to the database
(using attachment_fu if you're curious but that's probably not
relevant here):

VIEW
<%= image_tag '/photo/get_image/5' %>

CONTROLLER
def get_image
  @photo=Photo.find(params[:id])
  send_data(DbFile.find(@photo.db_file_id).data,
                            :type => @photo.content_type,
                            :file_name =>
@photo.filename,
                            :disposition => 'inline')
end

The images I'm saving are less than 100kb and easily handled by my
mysql column of db_file.data which is declared MEDIUMBLOB.

My problem is that the view works perfectly in production but not at
all in development -- in development I just get a broken image graphic
with a box and a red x.

Any ideas on how to troubleshoot this?  Since it doesn't seem to be my
code (it works fine in production) I'm at a loss on how to figure this
out.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 15:47
(Received via mailing list)
On Oct 8, 2:32 pm, Lastps <jasea...@gmail.com> wrote:
> I am using image_tag to load an image that I've saved to the database
> (using attachment_fu if you're curious but that's probably not
> relevant here):

I'd copy and paste that image link into the browser (ie yourserver,com/
photo/get_image/5) and see what the browser pulls out.

Fred
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 16:06
(Received via mailing list)
Thanks for the suggestion --
I get the same red box with the x.

On Oct 8, 8:47 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 16:19
(Received via mailing list)
On 8 Oct 2008, at 15:05, Lastps wrote:

>
> Thanks for the suggestion --
> I get the same red box with the x.
>
Do the logs indicate that an error occured ? If not and if you use the
tool of your choice to download the image, how do the bytes differ
from the bytes you would expect.

Fred
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 16:47
(Received via mailing list)
logs say that all is ok:
Sending data my_image.jpg
Completed in 0.09400 (10 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.08000 (85%) | 200 OK [http://localhost/photo/get_image/5]

Interesting question you ask about how do the bytes differ.  I guess I
first need to find a "tool of my choice" other than my two browsers
(IE and Firefox) -- any suggestions?

On Oct 8, 9:18 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 16:52
(Received via mailing list)
On 8 Oct 2008, at 15:47, Lastps wrote:

>
> logs say that all is ok:
> Sending data my_image.jpg
> Completed in 0.09400 (10 reqs/sec) | Rendering: 0.00000 (0%) | DB:
> 0.08000 (85%) | 200 OK [http://localhost/photo/get_image/5]
>
> Interesting question you ask about how do the bytes differ.  I guess I
> first need to find a "tool of my choice" other than my two browsers
> (IE and Firefox) -- any suggestions?

using the browser to save the image to disk would be one way.

Fred
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 16:54
(Received via mailing list)
i guess that's the point in that the browser is not displaying the
image -- it is just displaying the error gif, ie, a box with a red x
in it indicating that i can't load the image.

Fred, i really appreciate the time you're dedicating here...

On Oct 8, 9:51 am, Frederick Cheung <frederick.che...@gmail.com>
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 17:01
(Received via mailing list)
Just tried something else --
Changed disposition to "attachment" and used Firefox to successfully
download the file.  When I tried to open the file (in GIMP) I received
these error messages:
-- Premature end of JPEG file
-- Invalid JPEG file structure: missing SOS marker
So, I guess attachment_fu is not saving the files properly to my
db_file table...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 17:09
(Received via mailing list)
On 8 Oct 2008, at 16:00, Lastps wrote:

>
> Just tried something else --
> Changed disposition to "attachment" and used Firefox to successfully
> download the file.  When I tried to open the file (in GIMP) I received
> these error messages:
> -- Premature end of JPEG file
> -- Invalid JPEG file structure: missing SOS marker
> So, I guess attachment_fu is not saving the files properly to my
> db_file table...

that sounds like its getting truncated.

Fred
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 17:16
(Received via mailing list)
Yes -- seems like attachment_fu or mysql (?) might be truncating.
Weird though as the file size is not very large -- just 10kb.  In my
experience, truncation occurs because you are handling large files...

On Oct 8, 10:08 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 17:21
(Received via mailing list)
On 8 Oct 2008, at 16:15, Lastps wrote:

>
> Yes -- seems like attachment_fu or mysql (?) might be truncating.
> Weird though as the file size is not very large -- just 10kb.  In my
> experience, truncation occurs because you are handling large files...

I suppose you need to pinpoint where it happens: before the image hit
your app, before attachment fu tried to save it, when mysql was given
the image, after retrieval from the database etc...

Fred
Cd77b4f79f2699ded8a9eb6c9dc993e5?d=identicon&s=25 Lastps (Guest)
on 2008-10-08 19:44
(Received via mailing list)
Yep -- guess I'll step through and research the various ways to check
the size of the data at each place.  Thanks for your help!

On Oct 8, 10:20 am, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.