Shivam Rishi
Shivam Rishi

Reputation: 3

Delete file after 60seconds from gcs using Node js

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

Upvotes: 0

Views: 152

Answers (2)

SIDDHANT JOHARI
SIDDHANT JOHARI

Reputation: 82

var fileToBeDeleted = null;
var numberofMiliseconds = 60 * 1000;
fileToBeDeleted = bucket.file(baseContentUrl);
setTimeout(async () => {
  //you can do any operation you want to do after 60 section this line will execute.
  await fileToBeDeleted.delete();
}, numberofMiliseconds);

Upvotes: 0

Sebastián Espinosa
Sebastián Espinosa

Reputation: 2133

Something like this should work:

var fileToBeDeleted = bucket.file(baseContentUrl);

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

Hope it helps.

Upvotes: 0

Related Questions