如何在AdonisJS中修复“无效的JSON,仅支持对象和数组”?

时间:2019-07-02 19:38:43

标签: node.js angular adonis.js

我正在使用Adonisjs v5和Angular7。当我尝试从前端使用formData上传文件时,它将引发错误

  

错误:无效的JSON,仅支持对象和数组

我相信这是bodyParse错误,但我无法解决它。

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)"

这是我的Angular代码:-

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) => {

这是我的bodyParser配置:-

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: []

0 个答案:

没有答案