Ich benutze tatsächlich diese Arbeits Multer-Code zum Hochladen von Datei. Aber ich möchte mit ng-click() mehr Dinge von meinem Controller mit $ http Post senden. Eine einfache Eingabe mit einer Schaltfläche wird die beste sein.Multer Bild ohne Formular hochladen mit NG-Klick
html-Seite:
<form method="post" enctype="multipart/form-data" action="/productimage">
<p>
<input type="file" id="imgadd" name="upl"/>
</p>
<p>
<input type="submit"/>
</p>
</form>
Server-Seite:
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/products')
},
filename: function (req, file, cb) {
cb(null, Date.now() + '.jpg') //Appending .jpg
}
})
app.post('/productimage', multer({ storage: storage, limits: { fileSize: 200000} }).single('upl'), function(req,res, error){
console.log(req.body); //form fields
/* example output:
{ title: 'abc' }
*/
console.log(req.file.filename); //form files
/* example output:
{ fieldname: 'upl',
originalname: 'grumpy.png',
encoding: '7bit',
mimetype: 'image/png',
destination: './uploads/',
filename: '436ec561793aa4dc475a88e84776b1b9',
path: 'uploads/436ec561793aa4dc475a88e84776b1b9',
size: 277056 }
*/
res.status(204).end();
});