从 nextjs API 路由发送文件

sin*_*090 6 ajax node.js axios next.js

我使用 nextjs API 路由连接到外部 API

当我使用POST请求发送文件时,该文件在 API 路由中未正确处理,我得到422 Unprocessable Entity Error

当我仅发送文本时没问题,但是当我添加文件时会发生此错误。

我的请求

const data = new FormData();
        data.append('first_name', firstName);
        data.append('last_name', lastName);
        data.append('phone_number', phoneNumber);
        image && data.append('avatar', image);

        axios.post(`${API_ROUTE}`, data, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        .then(res=>{
            alert(JSON.stringify(res.data, null, 2));
        })
Run Code Online (Sandbox Code Playgroud)

我的 API 路线

    const config = {
        headers: {
            'Content-Type': req.headers['content-type']
        }
    };

    axios.post(address, req.body, config)
    .then(r=>{
        res.statusCode = 200
        res.json( r.data )
    })
    .catch(err=>{
        res.json(err)
    })
Run Code Online (Sandbox Code Playgroud)

在API Route发送到外部API的请求中,?文件内容中有一些,但是在从浏览器发送到API Route的请求中似乎有不同的字符