以下代码一直有效,直到我使用Google Cloud Platform为Android应用添加了凭据为止
exports.downloadurl = functions.storage.object().onFinalize(async (object) => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type.
const metageneration = object.metageneration; // Number of times metadata has been generated. New objects have a value of 1.
temp=filePath.split("/")
console.log(temp)
if(temp[1]==="Experience"){
storage.bucket(fileBucket).file(filePath).getSignedUrl({
action: 'read',
expires: '03-09-2491'
}).then(async (signedUrls) => {
await db.collection("user").doc(temp[0]).collection("Experience").doc(temp[2]).update({
Images: admin.firestore.FieldValue.arrayUnion(signedUrls[0]),
Picture:signedUrls[0]
})
return console.log(signedUrls)
// signedUrls[0] contains the file's public URL
}).catch(er =>{
return console.error("Error", er);
});
}
else if(temp[1]==="ProfilePic"){
storage.bucket(fileBucket).file(filePath).getSignedUrl({
action: 'read',
expires: '03-09-2491'
}).then(async (signedUrls) => {
await db.collection("user").doc(temp[0]).update({
ProfilePic:signedUrls[0]
})
return console.log(signedUrls)
// signedUrls[0] contains the file's public URL
}).catch(er =>{
return console.error("Error", er);
});
}
});
此后我收到此错误
错误错误:无法加载默认凭据。浏览至https://cloud.google.com/docs/authentication/getting-started了解更多信息。 在GoogleAuth.getApplicationDefaultAsync(/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:159:19) 在 在process._tickDomainCallback(internal / process / next_tick.js:229:7)