Ich möchte itemId in http Anfrage senden. wie es geht und was werde ich auf dem Server req sehen?Wie sende ich zusätzliche Daten in Anfrage?
hier Anfrage:
var fd = new FormData();
var itemId = scope.vm.item._id;
fd.append('file', scope.files[0]);
$http.post('http://localhost:8090/file-upload', fd, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined
}
});
Server
app.post('/file-upload', function(req, res, next) {
console.log("received file");
var pathFile = ' ';
var wId = "itemId";
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads/attachments');
pathFile = file.originalname;
},
filename: function (req, file,itemId, cb) {
cb(null, file.originalname);
console.log(itemId);
}
});
var upload = multer({ storage : storage }).single('file');
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading file.");
}
//save file path in work items doc.attachments
var path = './uploads/attachments/'+pathFile;
res.end("File is uploaded");
});
dienen Code hinzugefügt. Wie bekomme ich itemId auf der Serverseite?
Was ist mit 'fd.itemId = itemId'? – Dario
addedded backend – Serhiy
Sie können es einfach an die Formulardaten anhängen ... –