上传文件后,该函数将无法获取已签名的URL。
当file.getSignedUrl()被注释掉时,该功能起作用。
fstream.on('finish', function () {
var bucket = admin.storage().bucket();
// Upload a local file to a new file to be created in your bucket.
bucket.upload(tempFilePath,{ destination: filePath+fileName} ,function (err, file) {
if (!err) {
console.log("Uploaded: " + fileName);
fs.unlinkSync(tempFilePath);
return file.getSignedUrl({
action: 'read',
expires: '03-17-2500'
}, function(error, url) {
if (error) {
console.error(error);
return callback(new Error('could not get url: ', error))
}
console.log("Uploaded url : " + url);
return callback(null, url)
})
//return callback(null, "happy")
}else{
console.error("err: " + err);
return callback(new Error('could not upload'))
}
});
});
答案 0 :(得分:0)
为了了解签名的URL,请检查Google Cloud Storage Documentation
对于具有Node.js getSignedUrl的云功能,您可以use as a reference this example。
签名Blob所需的先决条件:
Identity and Access Management (IAM) API
has to be enabled in the project