Anmol Middha
Anmol Middha

Reputation: 97

Google drive nodejs api returns deleted files

I am using google drive api in my application. I have deleted the files from google drive but still listfiles function returns those deleted files. Is there any solution to avoid this. Here is function of my API

router.post('/', Authorise, (req, res, next) => {
const auth = req.auth;
const drive = google.drive({version: 'v3', auth});
drive.files.list({
    pageSize: 10,
    fields: 'nextPageToken, files(id, name)',
}, (err, rslt) => {
    if(err){
        res.status(500).json(err);
    }
    else{
        const files = rslt.data.files;
        if(files.length){
           res.status(200).json(files);
        }
        else{
            res.status(200).json({message: "No files found"})
        }
    }
});

});

Upvotes: 3

Views: 1528

Answers (3)

Daniel Carvalho
Daniel Carvalho

Reputation: 31

You could use this query:

await this.drive.files.list({
    q: 'trashed=false',
});

This way no trashed files from your folder are returned.

Upvotes: 3

Rahul Bagad
Rahul Bagad

Reputation: 123

Check the bin. You'll find deleted file there. That's why it's returning those files.

Upvotes: 0

Quentin C
Quentin C

Reputation: 1893

You can check in the Metadata (https://developers.google.com/drive/api/v3/reference/files) the value of the boolean 'trashed'.

Your problem may come from the difference between trashing and deleting:

  1. trashing: https://developers.google.com/drive/api/v2/reference/files/trash <- this is V2 API, I don't know if it works on v3
  2. deleting: https://developers.google.com/drive/api/v3/reference/files/delete

edit: you could also run this: https://developers.google.com/drive/api/v3/reference/files/emptyTrash

Upvotes: 4

Related Questions