I am using Adonisjs v5 and Angular 7. When I tried to upload file with formData from frontend then it throws the error
error: invalid JSON, only supports object and array
I believe it is bodyParse error, but I have not been able to resolve it.
Error: invalid JSON, only supports object and array
at parse (/Users/api/node_modules/co-body/lib/json.js:55:13)
at AsyncFunction.module.exports [as json] (/Users/api/node_modules/co-body/lib/json.js:41:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)"
Here is my Angular code:-
const formData: FormData = new FormData();
formData.append('name', this.name);
formData.append('image', this.image, this.image.name);
this.api.upload("/profile", formData,)
.subscribe((response: Response) => {
Here is my bodyParser config :-
json: {
limit: '1mb',
strict: true,
types: [
'application/json',
'application/json-patch+json',
'application/vnd.api+json',
'application/csp-report'
]
},
raw: {
types: [
'text/*'
]
},
form: {
types: [
'application/x-www-form-urlencoded'
]
},
files: {
types: [
'multipart/form-data'
],
maxSize: '20mb',
autoProcess: true,
processManually: []