Files API
Upload Files

Upload Files

Upload files to DealCloud image and binary fields. New attachment rows typically use upload_attachment(); updating an existing row’s IMAGE (16) or BINARY (13) field uses upload_file_to_entry_field() with raw bytes. HTTP is multipart via intapp-rest-client.

upload_attachment()

Create a new row on the attachments object and upload the file in one multipart request. The attachments object API name is often "Attachment" but is site-configurable.

from pathlib import Path
from dealcloud_sdk import DealCloud, DealCloudConfig
 
config = DealCloudConfig(
    siteUrl="yoursite.dealcloud.com",
    clientId=12345,
    clientSecret="your-secret",
)
dc = DealCloud.from_config_object(config)
 
path = Path("document.pdf")
result = dc.upload_attachment(
    "Attachment",
    path.read_bytes(),
    path.name,
    content_type="application/pdf",
)
entry_id = result["entry_id"]
doc_field_id = result["document_field_id"]

Parameters

ParameterTypeDescription
object_idstr | intAttachments object API name or ID
contentbytesRaw file bytes
file_namestrFilename sent to the API
content_typestr | NoneMIME type (inferred from extension if omitted)
titlestr | NoneOptional title for the new row (defaults to file_name)

upload_file_to_entry_field()

Upload bytes onto an existing row’s IMAGE or BINARY field.

from pathlib import Path
 
p = Path("logo.png")
dc.upload_file_to_entry_field(
    "Company",
    12345,
    "Logo",
    p.read_bytes(),
    p.name,
    content_type="image/png",
)

Parameters

ParameterTypeDescription
object_idstr | intObject containing the field
entry_idintExisting entry ID
fieldstr | intField API name or ID (must be IMAGE or BINARY)
contentbytesFile content
file_namestrFilename for the multipart part
content_typestr | NoneOptional MIME type

Uploading Images

For image fields (fieldType: 16):

from pathlib import Path
 
p = Path("logo.png")
dc.upload_file_to_entry_field(
    "Company",
    12345,
    "Logo",
    p.read_bytes(),
    p.name,
)
💡

Image fields accept common image formats: PNG, JPEG, GIF, WebP.

Uploading Attachments

from pathlib import Path
 
path = Path("contract.pdf")
result = dc.upload_attachment(
    "Attachment",
    path.read_bytes(),
    path.name,
    content_type="application/pdf",
)
attachment_id = result["entry_id"]
 
# Link to parent (field names vary by site)
dc.update_data("Deal", [{"EntryId": deal_id, "Contract": attachment_id}])

Batch Upload

from pathlib import Path
 
def batch_upload_attachments(dc, parent_object, parent_entry_id, attachment_field, file_paths):
    """Upload multiple files and link references on the parent."""
    attachment_ids = []
 
    for file_path in file_paths:
        path = Path(file_path)
        result = dc.upload_attachment(
            "Attachment",
            path.read_bytes(),
            path.name,
        )
        attachment_ids.append(result["entry_id"])
 
    dc.update_data(parent_object, [{"EntryId": parent_entry_id, attachment_field: attachment_ids}])
 
    return attachment_ids
 
files = ["doc1.pdf", "doc2.pdf", "image.png"]
ids = batch_upload_attachments(dc, "Deal", 12345, "Attachments", files)
print(f"Uploaded {len(ids)} files")

Upload from URL

Download from a URL and upload to DealCloud:

import httpx
 
def upload_from_url(dc, object_id, entry_id, field, url):
    response = httpx.get(url, timeout=60)
    response.raise_for_status()
 
    filename = url.split("/")[-1].split("?")[0] or "download.bin"
    content_type = response.headers.get("content-type", "").split(";")[0].strip() or None
 
    return dc.upload_file_to_entry_field(
        object_id,
        entry_id,
        field,
        response.content,
        filename,
        content_type=content_type,
    )
 
upload_from_url(
    dc,
    "Company",
    12345,
    "Logo",
    "https://example.com/logo.png",
)

delete_file()

Remove file content from a field (same entryfiles resource as download):

dc.delete_file(entry_id=12345, field_id="Logo")
⚠️

Deleting a file clears the binary on that field. For attachment references, you may also need to update the parent record’s reference field or delete the attachment row with delete_data() if that is your workflow.

Error Handling

from pathlib import Path
 
def safe_upload(dc, object_id, entry_id, field, file_path):
    path = Path(file_path)
 
    if not path.exists():
        raise FileNotFoundError(f"File not found: {file_path}")
 
    max_size = 100 * 1024 * 1024
    if path.stat().st_size > max_size:
        raise ValueError(f"File too large: {path.stat().st_size} > {max_size}")
 
    return dc.upload_file_to_entry_field(
        object_id,
        entry_id,
        field,
        path.read_bytes(),
        path.name,
    )
 
safe_upload(dc, "Attachment", 12345, "File", "document.pdf")

Common MIME Types

ExtensionContent Type
.pdfapplication/pdf
.docapplication/msword
.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
.xlsapplication/vnd.ms-excel
.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.pngimage/png
.jpg/.jpegimage/jpeg
.gifimage/gif

Related