Hi, Say I want to let the user upload multiple images/files in one form (I''m sticking them right in the DB). What''s a good strategy for creating the views and controllers for dealing with a potentially unspecified number of uploaded images/files? Thanks, Joe
How about an array of file uploads? I''ve seen this done with a few email clients, after you hit browse and select a file, a new file upload area areas below using javascript, the files are sent in an array Joe Van Dyk wrote:> Hi, > > Say I want to let the user upload multiple images/files in one form > (I''m sticking them right in the DB). What''s a good strategy for > creating the views and controllers for dealing with a potentially > unspecified number of uploaded images/files? > > Thanks, > Joe > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On Sun, 13 Feb 2005 17:35:53 -0800, Francisco Hernandez <lagcisco-b7MHZcQsHeJWk0Htik3J/w@public.gmane.org> wrote:> How about an array of file uploads? > > I''ve seen this done with a few email clients, after you hit browse and > select a file, a new file upload area areas below using javascript, the > files are sent in an arrayOh yeah, like gmail does it. Thanks, Also, how can I get an image that''s stored in the DB to be displayed in a html page?> > Joe Van Dyk wrote: > > Hi, > > > > Say I want to let the user upload multiple images/files in one form > > (I''m sticking them right in the DB). What''s a good strategy for > > creating the views and controllers for dealing with a potentially > > unspecified number of uploaded images/files? > > > > Thanks, > > Joe > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > >
On Sun, 2005-02-13 at 17:50 -0800, Joe Van Dyk wrote:> On Sun, 13 Feb 2005 17:35:53 -0800, Francisco Hernandez > <lagcisco-b7MHZcQsHeJWk0Htik3J/w@public.gmane.org> wrote: > > How about an array of file uploads? > > > > I''ve seen this done with a few email clients, after you hit browse and > > select a file, a new file upload area areas below using javascript, the > > files are sent in an array > > Oh yeah, like gmail does it. Thanks, > > Also, how can I get an image that''s stored in the DB to be displayed > in a html page?I haven''t done this with Ruby/Rails yet.. but in my php history, you basically have a script that connects to the db, grabs the BLOB and prints it out with the proper image headers. For example, with php: http://blog.planetargon.com/archives/27-Displaying-image-from- PostgreSQL-large-object-with-PHP.html I''m sure it''d be a pretty similar approach. Then in your html, you link to the image script/url like you would an image file. <img src="/path/to/script/"> -- /*************************************** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | robby-/Lcn8Y7Ot69QmPsQ1CNsNQ@public.gmane.org * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting & Development * --- Now hosting Ruby on Rails Apps --- ****************************************/
On 14.2.2005, at 03:50, Joe Van Dyk wrote:> > Oh yeah, like gmail does it. Thanks, > > Also, how can I get an image that''s stored in the DB to be displayed > in a html page?You can e.g. have an action like this class ImageController < ApplicationController def show @image = Image.find(@params["id"]) render_text image.content # content being the blob field in your db end end If you want to include the image name in the url, you can change id to file_name and use it in your image tags. If you do that, you also have to change the file_name field to unique (and/or validate_uniqueness of :file_name) and in case of an apache configuration change the .htaccess file so that it recognizes your filename format. By default it will only treat numbers as id and will think that your url is of form /module/controller/action (instead of /controller/action/filename). You need to change this line: RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ ?module=$1&controller=$2&action=$3 [QSA,L] to: RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ ?controller=$1&action=$2&id=$3 [QSA,L] Assuming you''re not using modules, of course. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Joe Van Dyk <joevandyk@...> writes:> > On Sun, 13 Feb 2005 17:35:53 -0800, Francisco Hernandez > <lagcisco@...> wrote: > > How about an array of file uploads? > > > > I''ve seen this done with a few email clients, after you hit browse and > > select a file, a new file upload area areas below using javascript, the > > files are sent in an array > > Oh yeah, like gmail does it. Thanks, > > Also, how can I get an image that''s stored in the DB to be displayed > in a html page?Here''s the method I''m using: f is an instance of my DB record, and data is the BLOB holding the image (or other file). send_data(f.data, :filename => f.filename, :type => f.content_type, :disposition => "inline") ... and here''s the rhtml that gets it: (get_image is the method that has the send_data, above) <img src="<%= url_for :action=> "get_image", :id => @id %>" />> > > > > Joe Van Dyk wrote: > > > Hi, > > > > > > Say I want to let the user upload multiple images/files in one form > > > (I''m sticking them right in the DB). What''s a good strategy for > > > creating the views and controllers for dealing with a potentially > > > unspecified number of uploaded images/files? > > > > > > Thanks, > > > Joe > > > _______________________________________________ > > > Rails mailing list > > > Rails@... > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >