gpt4 book ai didi

node.js - 不支持的内容类型图像/PNG

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:35 26 4
gpt4 key购买 nike

我正在尝试使用 NodeJS busboy 在服务器上上传图像文件我收到此错误:

Service Listening for request on: 8080
Error: Unsupported content type: image/png
at Busboy.parseHeaders (D:\ImageUploadService\node_modules\busboy\lib\main.j
s:66:9)
at new Busboy (D:\ImageUploadService\node_modules\busboy\lib\main.js:21:10)
at D:\ImageUploadService\server.js:15:15
at Layer.handle [as handle_request] (D:\ImageUploadService\node_modules\expr
ess\lib\router\layer.js:76:5)
at next (D:\ImageUploadService\node_modules\express\lib\router\route.js:100:
13)
at Route.dispatch (D:\ImageUploadService\node_modules\express\lib\router\rou
te.js:81:3)
at Layer.handle [as handle_request] (D:\ImageUploadService\node_modules\expr
ess\lib\router\layer.js:76:5)
at D:\ImageUploadService\node_modules\express\lib\router\index.js:234:24
at Function.proto.process_params (D:\ImageUploadService\node_modules\express
\lib\router\index.js:312:12)
at D:\ImageUploadService\node_modules\express\lib\router\index.js:228:12

下面是我的代码:

app.post('/uploadImage',function(req,res){
var alias=req.query.alias;
var imagetype=req.query.imagetype; //can be media/profile
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
var saveTo = ".\\Images\\"+alias+"\\"+imagetype+"\\"+filename;
if (fs.existsSync(saveTo)) {
file.pipe(fs.createWriteStream(saveTo));
}
else{
fs.mkdir(".\\Images\\"+alias+"\\"+imagetype,function(err){
saveTo=".\\Images\\"+alias+"\\"+imagetype;
file.pipe(fs.createWriteStream(saveTo));
});
}
});
busboy.on('finish', function() {
res.writeHead(200, { 'Connection': 'close' });
res.status(200).end();
});
return req.pipe(busboy);
});

我正在尝试使用 POSTMAN REST CLIENT 发出请求.

这是客户端的问题还是我必须在代码中进行更改。请注意,我在客户端( postman )上提到了 Content-Type: image/png

附带问题:另外,我有一种方法可以将图像存储为拇指??

最佳答案

Busboy 仅解析 application/x-www-form-urlencodedmultipart/form-data 请求。如果您要发送原始文件数据,则必须手动处理(这很简单,因为不涉及解析)。

关于node.js - 不支持的内容类型图像/PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26127007/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com