グリッド/FSに画像を保存していますが、UIを改善するために、特定の寸法に収まるようにすべての画像のサイズを変更したいと思います(ストレッチと押しつぶしの効果は範囲外です)。現在、画像は以下を使用して返されます...
FileProvider.prototype.streamFile = function(res, _id, contenttype){
var properId = this.db.bson_serializer.ObjectID.createFromHexString(_id)
res.contentType(contenttype)
var readstream = gfs.createReadStream(properId, {
"content_type": contenttype,
"id":true,
"metadata":{
"author": "Jackie"
},
"chunk_size": 1024*4 })
readstream.pipe(res)
}
これはうまく機能しますが、今は画像をインターセプトしてサイズ変更したいので、imagemagikを使用してサイズ変更を実行するよりもメモリ内でストリーミングすることを考えました(より良い方法があれば、遠慮なく教えてください)。
ただし、次のコードは画像の読み込みに失敗します...
FileProvider.prototype.streamFile = function(res, _id, contenttype){
var properId = this.db.bson_serializer.ObjectID.createFromHexString(_id)
res.contentType(contenttype);
var readstream = gfs.createReadStream(properId, {
"content_type": contenttype,
"id":true,
"metadata":{
"author": "Jackie"
},
"chunk_size": 1024*4 });
var writestream = new stream.Stream()
writestream.writeable = true
writestream.write = function(data){
console.log("Streaming.."+data)
}
writestream.pipe = function(src){
console.log("Piping:"+src)
}
writestream.end = function (data){
console.log(JSON.stringify(data))
console.log("Completed")
}
readstream.pipe(writestream)
}
これにより、以下がコンソールに出力されます。
未定義
完了
つまり、writeStreamにデータが書き込まれていません。誰かが私が間違っていることを見ることができますか?