使用postman上传binary数据会报Content-Type must be multipart/*
请问这是功能缺陷还是处于什么目的不允许直接接受二进制数据呢?
相关环境信息
- 操作系统: windows 10
- Node 版本: 8.9.4
- Egg 版本: 1.7.0

这是要求你加上对应的 header,可以看下 HTTP 协议
这是要求你加上对应的 header,可以看下 HTTP 协议
我想要的请求头content-type是: application/octet-stream
这个不可以支持吗?
Hello @bymaxchen. Please provide a reproducible example following the instruction.
Issues labeled by Need Reproduce will be closed if no activities in 7 days.
@bymaxchen,请根据这个说明提供最小可复现代码。
如果在 7 天内没有进展会被自动关闭。
用的this.ctx.getFileStream()? 二进制文件的话直接 this.ctx.req.pipe(fs.createWriteStream('./filename'))
getFileStream 只支持 mulitipart
如果你是自己的 header 的话,自己操作 req 的 stream,注意要做好 stream 的异常处理。
if (this.ctx.header['content-type'] === 'application/octet-stream') {
const stream = this.ctx.req
try {
const destStream = fs.createWriteStream(filePath)
await awaitWriteStream(stream.pipe(destStream))
} catch (err) {
await sendToWormhole(stream)
throw err
}
}
或者
const { pipeline } = require('stream')
try {
const stream = this.ctx.req
const destStream = fs.createWriteStream(filePath)
await pipeline(
stream,
destStream,
);
console.log('Pipeline succeeded');
} catch (err) {
console.error('Pipeline failed', err);
}
https://github.com/mafintosh/pump 可以关注下
@atian25 https://nodejs.org/en/docs/guides/backpressuring-in-streams/ .pump is only necessary for Nodejs 8.x or earlier, as for Node 10.x or later version, pipeline is introduced to replace for pump. This is a module method to pipe between streams forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.
@atian25 https://nodejs.org/en/docs/guides/backpressuring-in-streams/ .pump is only necessary for Nodejs 8.x or earlier, as for Node 10.x or later version, pipeline is introduced to replace for pump. This is a module method to pipe between streams forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.
cc @fengmk2