Reputation: 97
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
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
Reputation: 123
Check the bin. You'll find deleted file there. That's why it's returning those files.
Upvotes: 0
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:
- trashing: https://developers.google.com/drive/api/v2/reference/files/trash <- this is V2 API, I don't know if it works on v3
- 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