Commits

Alvaro Videla  committed b6c53f5

improves image response using cache and content type

  • Participants
  • Parent commits f6159a9

Comments (0)

Files changed (5)

File lib/image_storage.js

 ;
 
 function storeFile(tmpFile, filename, mimeType, callback) {
+    console.log("storeFile: ", mimeType);
     services.getMongoDbConnection(function(error, db) {
         var gs = new mongodb.GridStore(db, filename, "w", {
-            "contentType": mimeType,
-            "chunkSize": 1024*4
+            "content_type": mimeType,
+            "chunk_size": 1024*4
         });
 
         gs.open(function(error, gs) {

File lib/resize.js

                 dstPath: tmpPath,
                 width:   225
             }, function(err, stdout, stderr){
-                console.log('storeFile');
+                console.log('storing file');
+                console.log(Object.keys(gsData.gsObject));
                 image_storage.storeFile(tmpPath, filename, gsData.gsObject.contentType, function(error, data) {
                     console.log("deleting temporary file: ", tmpPath);
                     fs.unlink(tmpPath);

File npm-shrinkwrap.json

       "version": "0.7.1"
     },
     "mime": {
-      "version": "1.2.5"
+      "version": "1.2.7"
     },
     "http-status": {
       "version": "0.1.1"

File routes/fileServe.js

 ;
 
 function sendFile(res, data, mime, code) {
-    res.send(data, { 'Content-Type': mime }, code);
+    res.send(data, 
+             { 
+                 'Content-Type': mime,
+                 'Cache-Control': 'public, max-age=2592000'
+             }, code);
 }
 
 exports.serveFile = function(req, res, next) {
             console.log(error);
             res.send(404);
         } else {
+            console.log("serve file: ", gsData.gsObject.contentType);
             sendFile(res, gsData.binary, gsData.gsObject.contentType, HTTPStatus.OK);   
         }
     });

File routes/upload_image.js

 }
 
 function validImageType(mimeType) {
+    console.log("validImageType: ", mimeType);
     return ["image/jpeg", "image/png"].indexOf(mimeType) !== -1;
 }