We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
tfrysinger
4 years agoExplorer | Level 4
Problems using Dropbox Javascript SDK with API filesSearchV2
I am using a root folder to temporarily store files in what could be thousands of sub-folders under that root. I want to write a routine that would run daily from my website to "clean out" folders that are more than 30 days old. I have been able to get the Dropbox NPM module integrated and can call Dropbox via the Javascript API, but I'm seeing some odd results, and also am not sure the best way to go about efficiently finding the folders I need to delete each day.
Here the relevant part of the code that runs on the website:
const { Dropbox } = require('dropbox');
// Get DB access token
let token = await getSecret("dbat");
// Get folder for items
let xferfolder = "/" + await getSecret("dbpx");
// Get a dropbox object
let dbx = new Dropbox({ accessToken: token, fetch: fetch });
// Find 'files' (these will all be folders) to review
results = await dbx.filesSearchV2({"query": "pending_",
"options": {"path": xferfolder},
"match_field_options":{".tag":"filename"}});
One of the first things I noticed, was in the metadata returned to me it appears that the match was not done on filename as I requested in my match_field_options, but instead on filename_and_content:
"match_type": {".tag":"filename_and_content"},
"metadata": {".tag": "metadata",
"metadata": {".tag":"folder",
"id":"id:mnOYyqkJ95AAAAAAAAAsVw",
"name":"pending_20210304_frysingertad_at_gmail", "path_display":"/PendingSITXfers/pending_20210304_frysingertad_at_gmail",
"path_lower":"/pendingsitxfers/pending_20210304_frysingertad_at_gmail"}
}
"metadata": {".tag": "metadata",
"metadata": {".tag":"folder",
"id":"id:mnOYyqkJ95AAAAAAAAAsVw",
"name":"pending_20210304_frysingertad_at_gmail", "path_display":"/PendingSITXfers/pending_20210304_frysingertad_at_gmail",
"path_lower":"/pendingsitxfers/pending_20210304_frysingertad_at_gmail"}
}
Also, I noticed that folders do not have a 'last updated time' property, so I am not sure how I can find the folders which were created or updated more than 30 days ago, without examining each one every time and looking at the metadata of the files within the folder. I tried to come up with a folder naming scheme that would help in this regard - prefixing each folder with 'pending_' so I can use that as the search value, then a date of YYYYMMDD, but there does not seem to be a way to indicate a sort order on the return values? If there were I could then request the oldest be returned first and just loop through these until I reach a folder name that is < 30 days from today and then stop the loop. But alas, there doesn't seem to be a way to do this.
Can anyone suggest a better approach to programmatically finding all sub-folders within a directory that were created/last updated more than 30 days ago?
Thanks!
1 Reply
- Greg-DB4 years ago
Dropbox Community Moderator
To restrict search result to matching on the filename and not content, you should set FilesSearchOptions.filename_only to true. (By the way, your match_field_options doesn't look set correctly. That takes a FilesSearchMatchFieldOptions which only has a boolean include_highlights property.)
Anyway, the Dropbox API does not offer a modified time for folders, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.
Likewise, FilesSearchOrderBy currently does not support ordering by name, but we'll consider that a feature request as well.
Apologies I don't have better news for you!
About Discuss Dropbox Developer & API
Make connections with other developers814 PostsLatest Activity: 5 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!