【发布时间】:2021-09-27 10:00:25
【问题描述】:
我有一个 Firebase 云函数,它使用 GraphcisMagick 将缓冲区(从 PDF)转换为 PNG。当我尝试将此 PNG 缓冲区写入 Firebase 存储时,我得到一个文件存根,但没有内容(空文件)。我转换为 PNG 失败...
async function createThumbnail(newthumbname, mimetype, filebuffer) {
const file = bucket.file(newthumbname)
const thumbstream = file.createWriteStream({metadata:{contentType:mimetype}})
const gm = require('gm').subClass({imageMagick: true})
gm(filebuffer)
.toBuffer('png', (err, thumbbuffer)=>{
console.log(filebuffer)
console.log(thumbbuffer)
thumbstream.end(thumbbuffer)
})
}
传入createThumbnail()的filebuffer有内容,
<Buffer 25 50 44 46 2d 31 2e 33 0a 25 c4 e5 f2 e5 eb a7 f3 a0 d0 c4 c6 0a 33 20 30 20 6f 62 6a 0a 3c 3c 20 2f 46 69 6c 74 65 72 20 2f 46 6c 61 74 65 44 65 63 ... 6464 more bytes>
但是gm(filebuffer).toBuffer() 正在生产并用Error: Stream yields empty buffer 清空thumbbuffer
我在这里做错了什么?
【问题讨论】:
标签: imagemagick firebase-storage graphicsmagick createwritestream