Home > front end >  Express dosent take file even if i use fileUpload but Postman does
Express dosent take file even if i use fileUpload but Postman does

Time:03-25

i need to send file (image) with req.body data for express. And upload that image later. I use app.use(fileUpload()); instead of multer because its too difucult to understand how it works.

My axios looks like:

let form = new FormData();

    form.append('pfp', pfp);
    form.append("login", login);
    form.append('password', password);
    form.append("role", role);

    const { data } = await $auth_host.post('/api/user/registrateByAdmin', { form }, {
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    });

It doesnt work. Express in req.headers sees 'content-type' I will be grateful for your help.

CodePudding user response:

let form = new FormData();

    form.append('pfp', pfp);
    form.append("login", login);
    form.append('password', password);
    form.append("role", role);

    const { data } = await $auth_host.post('/api/user/registrateByAdmin', form , {
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    });

Try changing { form } to form

  • Related