2

The below code was working until I added a credential for an android app using Google Cloud Platform

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);


  });

  }

});

After which I am getting this error

Error Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:159:19) at at process._tickDomainCallback (internal/process/next_tick.js:229:7)

  • If you do a web search for that error message "Could not load the default credentials", you will find a lot of information about things that could cause it – Doug Stevenson Jan 21 '20 at 17:48

0 Answers0