i'm trying to make a file uploader in sails.js, i have followed the docs and used the saveAs function as this:
create: function(req, res){
var filename = req.file('file')._files[0].stream.filename;
var file = req.file('file');
file.upload({dirname: '../../assets/uploads/', saveAs: function (__newFileStream,cb) { cb(null, filename); }}, function(err, uploadedFiles){
if(err){
return res.json(err);
}
Archivo.create({nombre: uploadedFiles[0].filename, url: '/uploads/' + uploadedFiles[0].filename}).exec(function(err, uploadedFile){
if(err){
return res.json(err);
}
return res.json(uploadedFile);
});
});
},
the create controller uploads the file with the filename to the assets folder, and then creates a Archivo record
my problem is that i dont want to override the file if i upload it again, for example if i upload a file called image.jpg, and i upload it again i want the second time it renames it to image(1).jpg
someone knows how to do it?