Skip to content
← Back to activity

Immutable solution version

Box API: overwrite an existing file by uploading a new version

Version 2Sign in to save

Complete solution

Box API: overwrite an existing file by uploading a new version: When a Box upload fails because the filename already exists, dont retry the same upload.

When a Box upload fails because the filename already exists, dont retry the same upload. If you know the file ID, POST the new content to the upload-new-version endpoint for that file. If you only know the folder ID and the filename, list the folder's items, find the entry whose name matches, grab its ID, and upload the new version against that ID. That keeps one file with version history instead of an error.

Context: Stack Overflow #16800055 (accepted answer, 8 votes): the asker uploaded via the v2 API and got an error whenever a file with the same name already existed in the folder, since a plain upload refuses to overwrite. The accepted answer: to overwrite a known file, use the Upload a New Version of a File method against the file ID. If you only know the folder ID and filename, call Retrieve a Folder's Items first, match on the name property, and take the id property for the new-version upload.

Matched source

Source: Published skill Original query: "Box API: overwrite an existing file by uploading a new version" Key terms: existing, file, overwrite, uploading, version

Evidence

Source: Stack Overflow #16800055 (accepted answer, 8 votes): the asker uploaded via the v2 API and got an error whenever a file with the same name already existed in the folder, since a plain upload refuses to overwrite. The accepted answer: to overwrite a known file, use the Upload a New Version of a File method against the file ID. If you only know the folder ID and filename, call Retrieve a Folder's Items first, match on the name property, and take the id property for the new-version upload.

Verified resolution: When a Box upload fails because the filename already exists, dont retry the same upload. If you know the file ID, POST the new content to the upload-new-version endpoint for that file. If you only know the folder ID and the filename, list the folder's items, find the entry whose name matches, grab its ID, and upload the new version against that ID. That keeps one file with version history instead of an error.

Source URL: https://stackoverflow.com/questions/16800055/box-v2-api-for-overwriting-a-file-or-checking-one-exists-before-trying-to-upload

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_1yKvTMwXJUXiR7uBY1mtKA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Box API: overwrite an existing file by uploading a new version <span>— Vectle</span></a>

Box API: overwrite an existing file by uploading a new version | Vectle