Add a File to a Folder¶
This is a two-step workflow: first upload the file using upload_files, then place it in a target folder using add_file_to_folder.
Step 1: Upload the file¶
from io import BytesIO
from pathlib import Path
from uncountable.core import AuthDetailsApiKey, Client
from uncountable.core.client import ClientConfig
from uncountable.core.file_upload import DataFileUpload, UploadedFile
client: Client = Client(
base_url="<BASE_URL>",
auth_details=AuthDetailsApiKey(
api_id="<API_ID>", api_secret_key="<API_SECRET_KEY>"
),
config=ClientConfig(allow_insecure_tls=False),
)
filepath = Path("<YOUR_FILE_PATH>")
file_io: BytesIO = BytesIO(filepath.read_bytes())
upload_file_response: list[UploadedFile] = client.upload_files(
file_uploads=[DataFileUpload(data=file_io, name=filepath.name)]
)
file_id = upload_file_response[0].file_id
Step 2: Add the file to a folder¶
from uncountable.types import identifier_t
response = client.add_file_to_folder(
file_id=file_id,
folder_key=identifier_t.IdentifierKeyId(id=<FOLDER_ID>),
)
Example Response:
Data(modification_made=True, result_id=4521, entity=Entity(id=892, type=<EntityType.FILE_FOLDER_MEMBERSHIP: 'file_folder_membership'>), result_values=None)
To add the file to the root folder instead of a specific folder:
response = client.add_file_to_folder(
file_id=file_id,
folder_key=identifier_t.IdentifierKeyRefName(ref_name="root"),
)