gridfs-stream 上传文件不工作,但下载文件工作请给出解决方案
app.post('/file', function(req, res) {
var busboy = new Busboy({
headers: req.headers
});
var fileId = new mongo.ObjectID();
var file = filename();
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
if (!file) return res.send({
result: 'NO_FILE_UPLOADED This Error by not upload any file'
});
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
var writeStream = gfs.createWriteStream({
_id: fileId,
filename: my_file.txt,
mode: 'w',
chunkSize: 1024,
root: fs,
content_type: mimetype
});
// here how can i give a path to read stream ?
// File id is a mongodbid its ok. but what about file name
fs.createReadStream('/some/path').pipe(writestream);
}).on('finish', function() {
res.writeHead(200, {
'content-type': 'text/html'
});
res.end('<a href="http://localhost:49106/file/' + fileId.toString() + '">download file</a>');
});
req.pipe(busboy);//its working
});
gridfs-stream 文件上传代码不起作用 文件下载代码运行良好。如何在路径中设置 readstream 文件的路径。