[Fixed] Delete file after 60seconds from gcs using Node js

Issue

Here is the code to delete file but dont know how to delete it after certain time as there is no way in documentation.

 // Delete content file
     var fileToBeDeleted = null
     fileToBeDeleted = bucket.file(baseContentUrl)
     
     await fileToBeDeleted.delete()

Solution

Something like this should work:

var fileToBeDeleted = bucket.file(baseContentUrl);

setTimeout(async () => {
  await fileToBeDeleted.delete()
  // Do something after deleting.
}, 60 * 1000);

Hope it helps.

Leave a Reply

(*) Required, Your email will not be published