Open sylvanfrost opened 2 years ago
FormData doesn't support Blob. Try this instead. It works!
formData.append('name', JSON.stringify(request), { contentType: "application/json" });
headers: {
"Authorization": "Bearer " + accessToken,
...formData.getHeaders()
}
FormData doesn't support Blob. Try this instead. It works!
formData.append('name', JSON.stringify(request), { contentType: "application/json" });
headers: { "Authorization": "Bearer " + accessToken, ...formData.getHeaders() }
thank you for answer, but I already try this way before like this...
const generateRequest = () => {
// somecode
returnOptions.headers = { ...returnOptions.headers, ...FD.getHeaders(), ...options.headers };
returnOptions.payload = FD.getBuffer();
return returnOptions;
}
after this function, I send formData to my api but Joi cant validation aa
field like object (joi throw aa field -> "This field must be an object")
// my Joi Validation
const JoiValidation = Joi.Object({
aa: joi.Array().items(Joi.Object({
oa: Joi.string(),
ob: Joi.string()
}))
});
same the problem. I have a blob pdf file. I need to insert it into the form data. NestJS, axios.
Same problem, and according to the docs, FormData does support Blob: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
it's a nightmare with bytes \ blobs and form-data it simply doesn't work at all
Yeah, I don't get it how it so broken. I tried grabbing the Blob's stream()
and getReader()
after that but still nothing.
@anhvule
formData.append('name', JSON.stringify(request), { contentType: "application/json" });
headers: { "Authorization": "Bearer " + accessToken, ...formData.getHeaders() }
Thank you, this resolved my issue and it worked as expected!
the same problem, i solved it with formdata-node package
FormData doesn't support Blob. Try this instead. It works!
formData.append('name', JSON.stringify(request), { contentType: "application/json" });
headers: { "Authorization": "Bearer " + accessToken, ...formData.getHeaders() }
but if i need it as blob to send it to multer , how can i do it ?
environment
node - 15.7.0 (first version has blob as experimental) form-data - ^4.0.0
problem
why
My api develop by Hapi framework and validate by Joi. When api get a request Hapi will use Joi validate payload first (not my code), I need to validate some key in payload as my expected object joi exmaple
remark
JavaScript in html file can append blob
code
error
in html (work)