Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add file name logging

Also refactored file name handler into funtion
  • Loading branch information...
commit 0a7dd7c6deb0c264ffa6b96acc12aa4d0a1e9eca 1 parent 8c4423a
@oayandosu oayandosu authored
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';
}
Please sign in to comment.
Something went wrong with that request. Please try again.