Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multipart form parse error - Invalid boundary in multipart: None

I am very frustrated and could not find the soloution:

I am creating a project using angularjs and nodejs.I get image data from angular side in node js and send this data to further api.I got error

{
  "error": {
    "detail": "Multipart form parse error - Invalid boundary in multipart: None"
  }
}

here is my code in nodejs side:

var request = require('request');
    console.log(req.files);
var data = {

        website:'www.gamail.xom',
        contact_number:'dsdsd',
        services_offered:'dsadasd',
        contact_name:'dasdas',
        provider_category:'exchange',
        email:'[email protected]',
        image:req.files

    }
var api_url = global.common.base_url + 'vcard/1.0.0/visit_card/' + req.param('uuid') +'/';
    request({
        url: api_url,
        method: 'PUT',
        headers: {
            'Content-Type': 'multipart/form-data',
            'Authorization': 'Bearer '+req.cookies.apitoken
        },
        json: data

    }, function(error, response, body) {
        if(response.statusCode == 200 && !error){
            res.end(JSON.stringify(body));
        }else{          
            res.send(response.statusCode, { error: body });
        }
    });
}

In req.files i get

{ image:
   [ { fieldName: 'image[0]',
       originalFilename: 'icon_dd_chart_grey.png',
       path: 'C:\\Users\\karakuma\\AppData\\Local\\Temp\\op74_gLSzPs-_49aT1GF0si
7.png',
       headers: [Object],
       size: 1474,
       name: 'icon_dd_chart_grey.png',
       type: 'image/png' } ] }
like image 487
Karan Avatar asked Feb 17 '16 13:02

Karan


1 Answers

There is no need to mention the content type in header, fetch() will detect it's content type by itself.

let formData = new FormData()
formData.append("email", email);
formData.append("password", password);
formData.append("image", image);

const response = await fetch('http://localhost:8000/api/authentication/register/', {
                method: 'POST',
                headers: {'X-CSRFToken': csrftoken}, //django specific
                body: formData,
            });

like image 75
Yogesh Bisht Avatar answered Sep 20 '22 13:09

Yogesh Bisht