Skip to content

Commit 63dd9e9

Browse files
authored
Add the ability to replace files on file upload from API (#92)
1 parent f1082da commit 63dd9e9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/datalab_api/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,16 @@ def get_block(self, item_id: str, block_id: str, block_data: dict[str, Any]) ->
296296
block = self._post(block_url, json=block_request)
297297
return block["new_block_data"]
298298

299-
def upload_file(self, item_id: str, file_path: Path | str) -> dict[str, Any]:
299+
def upload_file(
300+
self, item_id: str, file_path: Path | str, replace_file_id: str | None = None
301+
) -> dict[str, Any]:
300302
"""Upload a file to an item with a given ID.
301303
302304
Parameters:
303305
item_id: The ID of the item to upload the file to.
304306
file_path: The path to the file to upload.
307+
replace_file_id: The ID of an existing file to replace with the uploaded file, if any.
308+
If provided, the new file will take the place of the old file in any blocks it was attached to.
305309
306310
Returns:
307311
A dictionary of the uploaded file data.
@@ -322,7 +326,7 @@ def upload_file(self, item_id: str, file_path: Path | str) -> dict[str, Any]:
322326
upload = self._post(
323327
upload_url,
324328
files=files,
325-
data={"item_id": item_id, "replace_file": None},
329+
data={"item_id": item_id, "replace_file": replace_file_id},
326330
expected_status=201,
327331
timeout=upload_timeout,
328332
)

0 commit comments

Comments
 (0)