HI @ncw
What a pleasure to get the chance to support rclone.
With our end of life for WebDav in April 2023, and our Box drive app only being available for windows and mac, rclone becomes the only option for linux users.
To your point, it all depends on the use case, mainly why you want to perform that check and what are you going to do after.
Nevertheless here is an option that come to mind, hopefully it will be applicable.
Assuming you have the folder id, the file name, and optionally it’s size, you can perform an HTTP OPTIONS
to the /files/content
endpoint.
We call this the pre-flight check.
In the body you pass:
{
"name": "File.mp4",
"size": 1024,
"parent": {
"id": "123"
}
}
If this returns a 200
it means the file does not exist.
if you get a 409 conflict
that can mean a couple of things, but those will be included in the rest of the error message:
- The file already exists
- You exceeded your quota
So for example with a file that exists:
curl --location --request OPTIONS 'https://api.box.com/2.0/files/content' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 1!M7xj...2QN' \
--data '{
"name": "test_upload.txt",
"size": 7409,
"parent": {
"id": "198948099055"
}
}'
Results in:
{
"type": "error",
"status": 409,
"code": "item_name_in_use",
"context_info": {
"conflicts": {
"type": "file",
"id": "1164548866790",
"file_version": {
"type": "file_version",
"id": "1268299299590",
"sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
"sequence_id": "0",
"etag": "0",
"sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"name": "test_upload.txt"
}
},
"help_url": "http://developers.box.com/docs/#errors",
"message": "Item with the same name already exists",
"request_id": "8kp70chhplprfrjr"
}
From here you can decide to upload a new file version, or abort the operation entirely.
You can learn more on the preflight check:
A quick note on the search option.
The major downsize of the search is that it can take minutes to index a recently created file.
The “exact” search query is not really that exact but helps a lot with the fuzzy search.
However you can restrict the search a lot further:
- Limit the search to a specific folder only [
ancestor_folder_ids
]
- Limit the search to look only in file name [
content_types
]
(by default it searches name, description, tags, comments and the first 10kbytes of the file)
- Limit the object returned to a specific type like only
files
[type
]
- Limit by file extension [
file_extensions
]
- Limit the amount of information returned [
fields
]
(this should improve performance, e.g. id,type,name,size)
Always check if the returned file name is in fact the same.
For more information checkout:
Let us know if this helps with your use case.
Cheers