I'm new to the BOX API so am using v2 of the API. I am making REST calls natively from my app.
I want to upload a file which may or may not have been previously uploaded. I know the parent folder ID and the file name. I need to either overwrite an existing file or at least make another call to see if the file already exists. I can see no way of doing either with the v2 API.
I can upload files without problem. But of course I get an error if the file already exists.
To me this is fairly basic stuff so perhaps I am missing something reasonably obvious?
name
property, which you can use for comparison, and an id
property, which you can use in conjunction with the Upload a New Version of a File method mentioned above.the file id of the file on box has the same name as the one you are uploading is outputted in the error message response to get it simply call $data->context_info->conflicts->id
then use that to overwrite the file with Upload a New Version of a File method
You re correct that in v2 of the API, uploading a file that already exists causes an error. What you can do is check if the file exists before uploading.
When you attempt to download a file, make a cURL call without the 'follow redirects' option. If the response is a 302 (with the actual download link), you know the file exists. If you get a 404, it does not exist.
For the above, it is important to specify that cURL should not follow redirects, otherwise if the file does exist, you will end up downloading it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With