Hello guys, I''m not sure if this is a complicated feat or not in rails. But it''s something I do in PHP so I''m assuming it might not be that hard. In PHP I wrote a simple tracking script that is dependant on mod_rewrite.. the same way rails is in routing.. anyway my script parses a fake URI that looks like it''s calling a .pdf file etc. fomr a directory that is the id of the actual file record in the DB. Here is an example: http://download.example.com/129/warranty_info.pdf My script then does the following: 1. It parses the URI into an array[ 129, "warranty_info.pdf" ] 2. It checks if the user is logged in via session.. if not it redirects 3. It grabs the actual file with that id from a path stored in the ''files'' table. 4. It opens the file on the server sets the header for the response and streams the file back to the user. The user gets a file back without knowing they are actually accessing a script... it''s seamless and works great for me. I use this script to protect sensitive documents on our corporate intranet etc. Can someone point me in the direction I need to be to accomplish something like this? I need to know the following: 1. Can you modify routing in a way that a specific controller has different routing rules from the defualts used in the application? 2. How do you stream files in rails / ruby? If anyone can get me started that''d be great! Thanks! - Jim
Jim, Take a look at this page on the Wiki. Specifically, you''ll be interested in the send_data and send_file methods mentioned towards the end of the page. http://wiki.rubyonrails.com/rails/show/HowtoUploadFiles Joe On Aug 7, 2005, at 4:26 AM, Jim Jeffers wrote:> Hello guys, > > I''m not sure if this is a complicated feat or not in rails. But > it''s something I do in PHP so I''m assuming it might not be that hard. > > In PHP I wrote a simple tracking script that is dependant on > mod_rewrite.. the same way rails is in routing.. anyway my script > parses a fake URI that looks like it''s calling a .pdf file etc. > fomr a directory that is the id of the actual file record in the DB. > > Here is an example: > http://download.example.com/129/warranty_info.pdf > > My script then does the following: > 1. It parses the URI into an array[ 129, "warranty_info.pdf" ] > 2. It checks if the user is logged in via session.. if not it > redirects > 3. It grabs the actual file with that id from a path stored in the > ''files'' table. > 4. It opens the file on the server sets the header for the response > and streams the file back to the user. > > The user gets a file back without knowing they are actually > accessing a script... it''s seamless and works great for me. I use > this script to protect sensitive documents on our corporate > intranet etc. > > Can someone point me in the direction I need to be to accomplish > something like this? I need to know the following: > > 1. Can you modify routing in a way that a specific controller has > different routing rules from the defualts used in the application? > > 2. How do you stream files in rails / ruby? > > If anyone can get me started that''d be great! Thanks! > > - Jim > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Wow! On Aug 7, 2005, at 9:51 AM, Joseph Hosteny wrote:> Jim, > > Take a look at this page on the Wiki. Specifically, you''ll be > interested in the send_data and send_file methods mentioned towards > the end of the page. > > http://wiki.rubyonrails.com/rails/show/HowtoUploadFiles > > Joe > > On Aug 7, 2005, at 4:26 AM, Jim Jeffers wrote: > > > >> Hello guys, >> >> I''m not sure if this is a complicated feat or not in rails. But >> it''s something I do in PHP so I''m assuming it might not be that hard. >> >> In PHP I wrote a simple tracking script that is dependant on >> mod_rewrite.. the same way rails is in routing.. anyway my script >> parses a fake URI that looks like it''s calling a .pdf file etc. >> fomr a directory that is the id of the actual file record in the DB. >> >> Here is an example: >> http://download.example.com/129/warranty_info.pdf >> >> My script then does the following: >> 1. It parses the URI into an array[ 129, "warranty_info.pdf" ] >> 2. It checks if the user is logged in via session.. if not it >> redirects >> 3. It grabs the actual file with that id from a path stored in the >> ''files'' table. >> 4. It opens the file on the server sets the header for the >> response and streams the file back to the user. >> >> The user gets a file back without knowing they are actually >> accessing a script... it''s seamless and works great for me. I use >> this script to protect sensitive documents on our corporate >> intranet etc. >> >> Can someone point me in the direction I need to be to accomplish >> something like this? I need to know the following: >> >> 1. Can you modify routing in a way that a specific controller has >> different routing rules from the defualts used in the application? >> >> 2. How do you stream files in rails / ruby? >> >> If anyone can get me started that''d be great! Thanks! >> >> - Jim >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >