no way to read image data from database

View: New views
12 Messages — Rating Filter:   Alert me  

no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


db----
   def self.up
    create_table :db_files,:force => true do |t|
      t.binary :data
      t.timestamps
    end
  end
db----

controller----
def find_db_file
    project=Project.find_by_id(params[:id])
    project_snapshot=project.project_snapshot
    send_data(project_snapshot.db_file.data,
                              :type  => project_snapshot.content_type,
                              :filename => project_snapshot.filename,
                              :disposition => 'inline')
end
controller----


view-------
 <%for p in @projects -%>
  <%=image_tag(url_for
(:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>
 <%end-%>
view-------



I try my best to display the image data in the database,but fail.It
seems everything is right.Even try from mysql to sqlite not works.This
really let me down.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Gregory Mazurek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't know exactly what errors you are seeing but...

On Sun, Nov 1, 2009 at 11:05 AM, daociyiyou <cheyu22@...> wrote:

db----
  def self.up
   create_table :db_files,:force => true do |t|
     t.binary :data
     t.timestamps
   end
 end
db---

I bet one of them is due to your not having content_type and filename in your table.
 
controller----
def find_db_file
   project=Project.find_by_id(params[:id])
   project_snapshot=project.project_snapshot
   send_data(project_snapshot.db_file.data,
                             :type  => project_snapshot.content_type,
                             :filename => project_snapshot.filename,
                             :disposition => 'inline')
end
controller----


view-------
 <%for p in @projects -%>
 <%=image_tag(url_for
(:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>
 <%end-%>
view-------



I try my best to display the image data in the database,but fail.It
seems everything is right.Even try from mysql to sqlite not works.This
really let me down.




--
www.abetaday.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


hi
  content_type and filename fields are in another table called
project_snapshots.I do  it according to the attachment_fu plugin
struction.I can just not display the image in the databse.

On Nov 2, 12:53 am, Gregory Mazurek <gregory.mazu...@...> wrote:

> I don't know exactly what errors you are seeing but...
>
> On Sun, Nov 1, 2009 at 11:05 AM, daociyiyou <chey...@...> wrote:
>
> > db----
> >   def self.up
> >    create_table :db_files,:force => true do |t|
> >      t.binary :data
> >      t.timestamps
> >    end
> >  end
> > db---
>
> I bet one of them is due to your not having content_type and filename in
> your table.
>
>
>
> > controller----
> > def find_db_file
> >    project=Project.find_by_id(params[:id])
> >    project_snapshot=project.project_snapshot
> >    send_data(project_snapshot.db_file.data,
> >                              :type  => project_snapshot.content_type,
> >                              :filename => project_snapshot.filename,
> >                              :disposition => 'inline')
> > end
> > controller----
>
> > view-------
> >  <%for p in @projects -%>
> >  <%=image_tag(url_for
> > (:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>
> >  <%end-%>
> > view-------
>
> > I try my best to display the image data in the database,but fail.It
> > seems everything is right.Even try from mysql to sqlite not works.This
> > really let me down.
>
> --www.abetaday.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


it seems -------<%=image_tag(url_for
(:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>-------
does not display the image but the image's alt words.when i right-
click the alt words to check the image,i get the the url for the
find_db_file action.Is this problem related with the database?

On Nov 2, 11:30 am, daociyiyou <chey...@...> wrote:

> hi
>   content_type and filename fields are in another table called
> project_snapshots.I do  it according to the attachment_fu plugin
> struction.I can just not display the image in the databse.
>
> On Nov 2, 12:53 am, Gregory Mazurek <gregory.mazu...@...> wrote:
>
> > I don't know exactly what errors you are seeing but...
>
> > On Sun, Nov 1, 2009 at 11:05 AM, daociyiyou <chey...@...> wrote:
>
> > > db----
> > >   def self.up
> > >    create_table :db_files,:force => true do |t|
> > >      t.binary :data
> > >      t.timestamps
> > >    end
> > >  end
> > > db---
>
> > I bet one of them is due to your not having content_type and filename in
> > your table.
>
> > > controller----
> > > def find_db_file
> > >    project=Project.find_by_id(params[:id])
> > >    project_snapshot=project.project_snapshot
> > >    send_data(project_snapshot.db_file.data,
> > >                              :type  => project_snapshot.content_type,
> > >                              :filename => project_snapshot.filename,
> > >                              :disposition => 'inline')
> > > end
> > > controller----
>
> > > view-------
> > >  <%for p in @projects -%>
> > >  <%=image_tag(url_for
> > > (:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>
> > >  <%end-%>
> > > view-------
>
> > > I try my best to display the image data in the database,but fail.It
> > > seems everything is right.Even try from mysql to sqlite not works.This
> > > really let me down.
>
> > --www.abetaday.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Attachment_fu works fine in :file_system mode, but
not in :db_file mode.  It seems to upload only about 45 bytes of data
instead of the entire image.Either t.binary :data or
t.binary :data,:limit => 10.megabyte can not works.
anyone can help me? Nearly a week time spent on it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I believe many peopel meet this problem
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


daociyiyou wrote:
> Attachment_fu works fine in :file_system mode, but
> not in :db_file mode.
[...]

Then don't use :db_file mode. :)  Images don't belong in the DB.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@...
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Marnen Laibow-Koser wrote:

> daociyiyou wrote:
>> Attachment_fu works fine in :file_system mode, but
>> not in :db_file mode.
> [...]
>
> Then don't use :db_file mode. :)  Images don't belong in the DB.
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> marnen@...

I was feeling masochistic about a year and a half ago, and had it
working in :db_file mode (the challenge of one of those "proof is left
as an exercise for the reader"), but the performance was so abysmal it
was quickly evident that it was not a viable, long-term solution. It can
be done, but I'm not even sure I have that 'tester' rails app on my
machine any longer.

Just store your images on the file system, and get on with the fun
things...
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by daociyiyou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks! My server do not approve the file system store,that is why
using the db_file.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


What does your generated HTML look like for the view in question?

What you have looks familiar, but image_tag may be messing you up.

Can you get it to work if you ignore the helper and write the
appropriate html to wrap the inline content yourself?
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi
>     send_data(project_snapshot.db_file.data,
>                               :type  => project_snapshot.content_type,
>                               :filename => project_snapshot.filename,
>                               :disposition => 'inline')

  Can you try here StringIO.new(project_snapshot.db_file.data)?




Sijo
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: no way to read image data from database

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


daociyiyou wrote:
> Thanks! My server do not approve the file system store,that is why
> using the db_file.

Find a different server, then, or use S3.  Even if you can get this to
work, you're asking for trouble.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@...
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---