[英]How to post images to NodeJS server form Angular 2+
I have a NodeJS rest-API that accepts images and content like text in the same function. 我有一个NodeJS rest-API,它可以在同一函数中接受图像和类似文本的内容。
I'm using multer in my NodeJS server to handle the images, more precisely I have the same example from below just I have content with it also. 我在NodeJS服务器中使用multer来处理图像,更确切地说,我也有下面的示例,只是我也对此感到满意。
var cpUpload = upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'gallery', maxCount: 8 }])
app.post('/cool-profile', cpUpload, function (req, res, next) {
// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
//
// e.g.
// req.files['avatar'][0] -> File
// req.files['gallery'] -> Array
//
// req.body will contain the text fields, if there were any
})
How can I send the images form Angular 4 frontend page to NodeJS backend. 如何将Angular 4前端页面中的图像发送到NodeJS后端。
Thank you! 谢谢!
Send images files via formdata : 通过formdata发送图像文件:
let myForm = new FormData();
myForm.append('avatar', image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.