Skip to content

Instantly share code, notes, and snippets.

@dileephell
Last active December 14, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dileephell/5011503 to your computer and use it in GitHub Desktop.
Save dileephell/5011503 to your computer and use it in GitHub Desktop.
var uuid=require('node-uuid');
var tmp_path = req.files.uploadimgs.path,uuid;
console.log(uuid);
// set where the file should actually exists - in this case it is in the "images" directory
var target_path = './upload/work/' +req.files.uploadimgs.name+uuid();
// move the file from the temporary location to the intended location
fs.rename(tmp_path, target_path, function(err) {
if (err) throw err;
console.log('cfgh');
// delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
fs.unlink(tmp_path, function() {
if (err) throw err;
console.log('fdsggghggff');
res.send('File uploaded to: ' + target_path + ' - ' + req.files.uploadimgs.size + ' bytes');
});
});
};
its output is
22 Feb 12:47:53 - [nodemon] starting `node test.js`
server is working at "127.0.0.1:6000"
{ [Function: v4]
v1: [Function: v1],
v4: [Circular],
parse: [Function: parse],
unparse: [Function: unparse],
BufferClass:
{ [Function: Buffer]
poolSize: 8192,
isBuffer: [Function: isBuffer],
byteLength: [Function],
concat: [Function],
_charsWritten: 20 } }
cfgh
fdsggghggff
and in the work folder i m having the image with the name of "myImage.jpgc87fda2b-10ec-49eb-bc96-60d60f293098 "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment