通过Admin SDK(NodeJs后端)将文件存储在Firebase存储中时,文件存储相对较快,但下载URL最多需要10秒才能响应承诺。该下载URL正在传递到前端,因此,您可以想象,10秒的等待时间不会减少它:(。我如何加快这一步?
我正在上传的文件大小为 3MB ,并且较小
uploadImage(req, res) {
console.log("Uploading Post Images")
const file = req.file;
const name = file.originalname;
const bucketFile = db.bucket.file('/post_pics/' + name);
const fileMime = mime.lookup(name);
let uuid = UUID();
var options = {
metadata: {
contentType: fileMime,
metadata: {
firebaseStorageDownloadTokens: uuid
}
}
}
bucketFile
.save(new Buffer(file.buffer), options)
.then(() => {
console.log("Success!")
URL = 'https://firebasestorage.googleapis.com/v0/b/weatheru-
343ac.appspot.com/o/' + encodeURIComponent(bucketFile.metadata.name) + '?
alt=media&token=' + uuid;
res.status(200).json({
status: 'success',
data: URL
})
})
.catch(err => {
console.log("Failed!")
res.status(500).json({
status: 'error',
errors: err,
});
});
}