我目前正在我的应用程序中创建一个文件上传系统.我的后端是Sails.js(10.4),它作为我单独的前端(Angular)的API.
我选择将我上传的文件存储到我的MongoDB实例,并使用sails的内置文件上传模块Skipper.我正在使用适配器skipper-gridfs(https://github.com/willhuang85/skipper-gridfs)将文件上传到mongo.
现在,上传文件本身不是问题:我在我的客户端上使用dropzone.js,它将上传的文件发送到/ api/v1/files/upload.文件将上传.
为了实现这一点,我在FileController中使用以下代码:
module.exports = {
upload: function(req, res) {
req.file('uploadfile').upload({
// ...any other options here...
adapter: require('skipper-gridfs'),
uri: 'mongodb://localhost:27017/db_name.files'
}, function(err, files) {
if (err) {
return res.serverError(err);
}
console.log('', files);
return res.json({
message: files.length + ' file(s) uploaded successfully!',
files: files
});
});
}
};
Run Code Online (Sandbox Code Playgroud)
现在问题是:我想在上传文件之前先处理这些文件.特别是两件事:
我不知道从哪里开始或如何实现这种功能.所以任何帮助将不胜感激!