| 
									
										
										
										
											2011-08-18 05:43:33 +00:00
										 |  |  | require 'mongo' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GridfsController < ActionController::Metal | 
					
						
							| 
									
										
										
										
											2011-08-25 00:13:38 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-08-18 05:43:33 +00:00
										 |  |  |   def serve | 
					
						
							| 
									
										
										
										
											2012-04-01 15:39:49 +00:00
										 |  |  |     gridfs_path = env["PATH_INFO"].gsub("/gridfs/", "").force_encoding("UTF-8") | 
					
						
							| 
									
										
										
										
											2011-08-18 05:43:33 +00:00
										 |  |  |     begin | 
					
						
							|  |  |  |       gridfs_file = Mongo::GridFileSystem.new(Mongoid.database).open(gridfs_path, 'r') | 
					
						
							|  |  |  |       self.response_body = gridfs_file.read | 
					
						
							|  |  |  |       self.content_type = gridfs_file.content_type | 
					
						
							|  |  |  |     rescue | 
					
						
							|  |  |  |       self.status = :file_not_found | 
					
						
							|  |  |  |       self.content_type = 'text/plain' | 
					
						
							|  |  |  |       self.response_body = '' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-25 00:13:38 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-08-18 05:43:33 +00:00
										 |  |  | end |