Node.js NodeJS Multer NGINX上载错误:位置0处的JSON中出现意外令牌

Node.js NodeJS Multer NGINX上载错误:位置0处的JSON中出现意外令牌,node.js,express,nginx,axios,multer,Node.js,Express,Nginx,Axios,Multer,我无法使用Multer将图像上载到我的NodeJS后端。我使用Axios将包含图像和一些数据的FormData对象发布到我的NGINX代理服务器,最终将其保存在我的数字海洋空间中。在我的开发环境中,一切都可以完美地工作,但当我尝试在生产环境中上载文件时,会出现以下错误: SyntaxError: Unexpected token - in JSON at position 0 at JSON.parse (<anonymous>) at createStrictSyn

我无法使用Multer将图像上载到我的NodeJS后端。我使用Axios将包含图像和一些数据的FormData对象发布到我的NGINX代理服务器,最终将其保存在我的数字海洋空间中。在我的开发环境中,一切都可以完美地工作,但当我尝试在生产环境中上载文件时,会出现以下错误:

SyntaxError: Unexpected token - in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError ...
快递和快递:

const endpoint = new aws.Endpoint("sfo2.digitaloceanspaces.com/");

const s3 = new aws.S3({
  endpoint,
  accessKeyId: config.DO_SPACE_ACCESS_KEY,
  secretAccessKey: config.DO_SPACE_SECRET_KEY
});

var productionUpload = multer({
  storage: multerS3({
    s3,
    bucket: "bucket-name",
    acl: "public-read",
    contentType: multerS3.AUTO_CONTENT_TYPE,
    filename: (req, file, cb) => {
      cb(
        null,
        file.fieldname + "-" + Date.now() + `${path.extname(file.originalname)}`
      );
    }
  })
});

app.post(
  "/create_post",
  productionUpload.single("file"),
  verifyToken,
  create_post
);

Nginx配置:

 location  API/ {
        proxy_pass http://localhost:3000/;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Content-Type 'application/json';

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }



我已经用尽了这个网站和其他网站上的所有选项。提前谢谢你

这可能是一个问题,因为您将内容类型作为application/json传递,并上载内容类型不是json的文件。删除此标题并重试一次

 location  API/ {
        proxy_pass http://localhost:3000/;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Content-Type 'application/json';

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }