Skip to content
Browse files

Add file name logging

Also refactored file name handler into funtion
  • Loading branch information...
1 parent 8c4423a commit 0a7dd7c6deb0c264ffa6b96acc12aa4d0a1e9eca @oayandosu oayandosu committed Apr 6, 2012
Showing with 13 additions and 6 deletions.
  1. BIN public/snaps/image_2012-04-06T22:09:14.746Z.png
  2. +13 −6 server.js
View
BIN public/snaps/image_2012-04-06T22:09:14.746Z.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
19 server.js
@@ -29,19 +29,26 @@ app.post('/snap', function(req, res) {
imageData = imageData.replace(/^data:image\/png;base64,/,"");
var buffer = new Buffer(imageData, 'base64'),
- time = new Date().toJSON();
+ filename = nameFile();
- fs.writeFile('./public/snaps/images_' + time + '.png', buffer, function(err) {
- if (err) console.log('error saving');
- else console.log('it saved');
+ fs.writeFile(filename, buffer, function(err) {
+ if (err) {
+ console.log('error saving');
+ }
+ else {
+ console.log('It saved!');
+ res.send(filename);
+ }
});
-
- res.send(imageData);
});
});
function nameFile() {
+ var path = './public/snaps/',
+ timestamp = new Date().toJSON();
+
+ return path + 'image_' + timestamp + '.png';
}

0 comments on commit 0a7dd7c

Please sign in to comment.
Something went wrong with that request. Please try again.