我正在开发一个API,该API通过Axios.post将在Vue.js中创建的Blob对象发送到Express.js。

Vue.js

...
const blobObject = new Blob([content]);

axios.post(`http://localhost:3000/post`, blobObject)
    .then(
         (response) => {
              console.log('Successfully Save API')
          },
          (err) => {
              console.error(err)
          }
    )



但是,Blob对象通过req.body出现,但未定义通过req.body.blobObject输出。

Express.js
...

router.post('/', (req, res, next) => {
    const { blobObject } = req.body;
    console.log(blobObject) // undefined

    console.log(req.body) // Blob Object OK
    // req.body
    // [Object: null prototype] { ...String in Blob Object... }
}


我的代码有什么问题?

最佳答案

const blobObject = new Blob([content])
const data = new FormData()
data.append('file', blobObject)

axios.post('http://localhost:3000/post', data)


Related answer

10-01 13:56