Search code examples
box-api

BOX v2 API for overwriting a file or checking one exists before trying to upload


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.

  1. In v1 there was a way to specify an overwrite in the upload call. No such thing in v2 as far as I can tell. Am I correct? Will an overwrite flag get added back into the API?
  2. Given a file name how do I see if this already exists in a specific parent folder?

To me this is fairly basic stuff so perhaps I am missing something reasonably obvious?


Solution

    1. You are correct that the Upload a File method will fail if a file with the same name already exists in the folder. If you want to overwrite a known file, consider using the Upload a New Version of a File method.
    2. If you know the ID of the parent folder, you can use the Retrieve a Folder's Items method to get a list of the items in that folder. Each item will have a 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.