STORING AND SERVING IMAGES WITH



GRIDFS

           Mr. Mongo Mark
            @m_smalley
z




MEDIA STORAGE & SERVING
   ( without using a file-system )
z




WHY DO FILESYSTEMS SUCK ...?
     ( at serving media on the web )
POOR AT SCALING
( with tedious back-ups and I/O bottlenecks )
POOR METADATA
( lacking built-in meta storage and data queries )
STRICT CONVENTIONS
 ( naming and directory limits cause poor reliability )
GRIDFS ALSO USES REPLICA-SETS
 ( all media backed-up and load-balanced in chunks )
GRIDFS ALSO USES REPLICA-SETS
 ( all media backed-up and load-balanced in chunks )
EXAMPLE PHP

CODE
GETTING IMAGES OUT
www.your-domain.com/images/tron.jpg
        ( assuming .htaccess is redirecting within folder )

  // Get Filename
$slug = $_SERVER[‘REQUEST_URI’];

// Define Database
$db = $m->$options['db_name'];

// Get GridFS
$grid = $db->getGridFS();

// Get Image
$image = $grid->findOne(
    array("name" => $slug)
);

// Display Image
header('Content-type: '.$image->file['type']);
echo $image->getBytes();
STALK ME ON TWITTER IF YOU LIKE


@m_smalley



          Twitter Hashtag #klmug
         KL MUG on Twitter @klmug

            KL MUG on Facebook
  https://www.facebook.com/groups/klmug/

Serving Images with GridFS

  • 1.
    STORING AND SERVINGIMAGES WITH GRIDFS Mr. Mongo Mark @m_smalley
  • 2.
    z MEDIA STORAGE &SERVING ( without using a file-system )
  • 3.
    z WHY DO FILESYSTEMSSUCK ...? ( at serving media on the web )
  • 4.
    POOR AT SCALING (with tedious back-ups and I/O bottlenecks )
  • 5.
    POOR METADATA ( lackingbuilt-in meta storage and data queries )
  • 6.
    STRICT CONVENTIONS (naming and directory limits cause poor reliability )
  • 7.
    GRIDFS ALSO USESREPLICA-SETS ( all media backed-up and load-balanced in chunks )
  • 8.
    GRIDFS ALSO USESREPLICA-SETS ( all media backed-up and load-balanced in chunks )
  • 9.
  • 10.
    www.your-domain.com/images/tron.jpg ( assuming .htaccess is redirecting within folder ) // Get Filename $slug = $_SERVER[‘REQUEST_URI’]; // Define Database $db = $m->$options['db_name']; // Get GridFS $grid = $db->getGridFS(); // Get Image $image = $grid->findOne( array("name" => $slug) ); // Display Image header('Content-type: '.$image->file['type']); echo $image->getBytes();
  • 11.
    STALK ME ONTWITTER IF YOU LIKE @m_smalley Twitter Hashtag #klmug KL MUG on Twitter @klmug KL MUG on Facebook https://www.facebook.com/groups/klmug/

Editor's Notes