有人能说明我如何处理发送到featherjs的文件吗?
我以下客户端完全与featherjs分开,但是在我的服务中实际访问所述文件没有问题。
var req = request.post('http://uploadhost/upload').set('Authorization', 'Bearer '+this.props.authtoken);
this.state.files.forEach(file => {
req.attach(file.name, file);
});
req.end(this.callback);
答案 0 :(得分:0)
FeathersJS只是扩展了express。如果要解码表单数据(看起来像你一样),则需要添加一个多部分解析器,例如multer。
const multer = require('multer');
const multipartMiddleware = multer();
// Upload Service with multipart support
app.use('/uploads',
// multer parses the file named 'uri'.
// Without extra params the data is
// temporarely kept in memory
multipartMiddleware.single('uri'),
// another middleware, this time to
// transfer the received file to feathers
function(req,res,next){
req.feathers.file = req.file;
next();
},
blobService({Model: blobStorage})
);
最终,feathers使用their blob service创建文件。
const blobService = require('feathers-blob');
const blobStorage = fs(__dirname + '/uploads');
我希望这有助于澄清我的评论。