【发布时间】:2019-06-09 01:48:09
【问题描述】:
到目前为止我有这个:
app.get('/:image/:size.:ext', (req, res) => {
const remote = bucket.file(`${req.params.image}/${req.params.size}.${req.params.ext}`)
if (req.query.download == 'true') {
res.set('Content-Type', 'image/jpg')
res.set('Content-Disposition', `attachment; filename="${req.params.image}.${req.params.size}.${req.params.ext}";` )
res.set('Content-Transfer-Encoding', 'binary')
// header("Content-Length: ".filesize($filename))
}
// if (isProd)
// res.set('Cache-Control', 'public, max-age=604800')
remote.createReadStream({ validation: false })
.on('error', error => {
console.log(error)
res.send(`data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7`)
})
.pipe(res)
})
在那个download=true 块中,我不确定如何获取文件大小,如果它以某种方式通过remote 流传递,或者我是否应该将它存储在某个数据库中,或者以某种方式获取。
【问题讨论】:
-
我想您是在问如何检索 GCS 对象的大小?如果是这样,那么我们可以查看返回的元数据的 size 属性。这是对应API的链接...cloud.google.com/nodejs/docs/reference/storage/2.5.x/…
标签: node.js image google-cloud-platform download google-cloud-storage