简体   繁体   中英

Cannot read property 'file' of undefined

backend code

.post((req, res) => {
            let EDFile = req.files.file;
            EDFile.mv(`./files/${EDFile.name}`, err => {
                if (err) return res.status(500).send({ message: err });
                req.body.imagen = "http://localhost:5000/imagenes/" + EDFile.name;
                database.create(req.body)
                    .then(result => res.json(result))
                    .catch(error => {
                        res.status(412).json({ msg: error });
                    });
            });
        });

angular code

   onUploadFinish(event) {
    console.log(event);
    this.image=new ImageSelected;
    this.image.image =event;
    this.image.name=event.file.name;
     }


   sendImage(){
    const formData = new FormData();

    console.log(formData.get('file'));
       this.http.post("http://localhost:5000/databases",{
         body:{
           file:this.image,
           nombre:"nombre",
           url:"nombre"
         }
       }).subscribe((d)=>{
         console.log(d)
       })
   }

I am trying to send the information through an angular post but in all my sales attempts I cannot read the 'file' property of undefined

I hope any help

Try: let EDFile = req.file;

I don't see that you have defined files in the body, on the client-side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM