5
Hello anyone ever used multer(express/nodejs module) to upload files? If so, how did you manage to capture the events of callbacks (onFileUploadStart and onFileUploadComplete)? Theoretically I am using correctly but at no time are events called...
Sample code:
'use strict';
//DEFINO AS DEPENDENCIAS
var express = require('express');
var multer = require('multer');
var uploadRealizado = false;
var servidor = express();
//CONFIGURO O MULTER NA INSTANCIA DO EXPRESS(no caso nosso servidor)
var upload = multer({
dest: './testeUpload/',
rename: function(nomeCampo, nomeArquivo) {
return nomeArquivo+Date.now();
},
onFileUploadStart: function(arquivo) {
console.log('COMEÇOU O UPLOAD');
},
onFileUploadComplete: function (arquivo) {
console.log('TERMINOU O UPLOAD');
uploadRealizado = true;
}
});
//APLICANDO AS ROTAS
servidor.get('/', function(requisicao, resposta) {
resposta.sendfile('./home.html');
});
servidor.post('/api/photo', upload.single('avatar'), function(requisicao, resposta) {
console.log('STATUS UPLOAD' + uploadRealizado);
console.log('ARQUIVOS', requisicao.file | requisicao.files);
if (uploadRealizado) {
resposta.send('foto enviada');
}
resposta.send('foto não enviada');
});
//INICIO O SERVIDOR
servidor.listen(3000, function(){
console.log('servidor rodando na porta 3000');
});
Att,
I don’t see those callbacks in the documentation you can point out where you saw that the woman has callbacks?
– Sergio
so... I saw in almost every tutorial involving Multer... : https://codeforgeek.com/2014/11/file-uploads-using-node-js/ http://stackoverflow.com/questions/26702869/multer-not-uploading-files-when-i-include-logic-onfileuploadstartnodejs *As documentation is not always a strong of nodejs modules I ended up going with most
– Douglas dos Santos