2
mongodbにファイルのリストを格納するプログラムをnodejsでコーディングしようとしています。それはうまくいきますが、contentTypeメタデータを常にバイナリ/オクテットストリームとして保存し、実際のMIMEタイプを保存したいと思うという問題があります。私はreadTimeの前にMIMEタイプを取得しようとしていますが、たとえcontentType(たとえば "image/jpeg")をハードコーディングしても、常にメタデータを "バイナリ/オクテットストリーム"として保存します。gridfs-streamは常に "contentType:binary/octet-stream"でファイルを保存します
私のコードは次のとおりです。
files.forEach(function(f) {
var conn = mongoose.createConnection(db);
conn.once('open', function() {
var gfs = Grid(conn.db);
var writeStream = gfs.createWriteStream({
filename: f.location,
mode: 'w',
contentType: 'image/jpeg'
});
writeStream.on('finish', function() {
console.log('Storing', f.location, 'OK');
return;
})
.on('error', function(data) {
console.log('Error', f.location, data)
});
fs.createReadStream(path.join(__dirname, 'files', f.location), 'utf-8')
.pipe(writeStream);
});
});
任意のアイデアは、ご回答いただきありがとうございます