18 lines
		
	
	
		
			508 B
		
	
	
	
		
			Ruby
		
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			508 B
		
	
	
	
		
			Ruby
		
	
	
	
| require 'mongo'
 | |
| 
 | |
| class GridfsController < ActionController::Metal
 | |
|   
 | |
|   def serve
 | |
|     gridfs_path = (params[:path]+'.'+params[:format]).gsub("/gridfs/", "").force_encoding("UTF-8")
 | |
|     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
 | |
|   
 | |
| end |