Getting this error in the given code. I am calling this method on file upload and it is going to catch block.
ERR: TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type object
try{
request
.post(url)
.set(postHeaders)
.send(postData)
.end(function (err, response) {
if(err) {
console.log(err);
res.send(errorJson);
return;
}
res.set(response.header);
res.send(response.text);
});
} catch(err){
console.log("error" , err)
}
The header is
'content-type': 'multipart/form-data;'
From the looks of it you are using superagent
to perform the upload. Since you're intending to do a multipart/form-data
upload, you cannot use .send()
. From the docs :
Multipart requests SuperAgent is also great for building multipart requests for which it provides methods.attach() and.field().
When you use.field() or.attach() you can't use.send() and you must not set Content-Type (the correct type will be set for you)
So you need to change your code to:
request
.post(url)
.field(<setYourFieldDataHere>) // or use .attach() if you want to upload files
//
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.