API Reference: Core Documentation Handling File Uploads and Assets

Learn how to securely upload files and import external assets into your documentation projects using the API. Whether you are uploading local files directly from a user's device or pulling in existing assets from the web, the API provides dedicated endpoints to handle your media efficiently.

Upload vs. Import

Choose Direct Uploads when you have a local file that needs to be securely transferred to the system. Choose Asset Imports when the file is already hosted on the public internet and you just want the system to fetch it.

How file management works

Handling files in the API is divided into two distinct workflows. The Mermaid diagram below illustrates the difference between a direct file upload (a secure, multi-step process) and an asset import (a simple, single-step process).

sequenceDiagram
    participant Client
    participant API as GitDocAI API
    participant Storage as Cloud Storage
    
    rect rgb(240, 248, 255)
    Note over Client, Storage: Direct File Upload Workflow
    Client->>API: 1. Request signed upload URL
    API-->>Client: Returns secure URL
    Client->>Storage: 2. Upload file directly to Storage
    Client->>API: 3. Finalize the upload
    API-->>Client: File resource created
    end
    
    rect rgb(245, 245, 245)
    Note over Client, API: Asset Import Workflow
    Client->>API: 1. Send public URL to import
    API-->>Client: Asset imported successfully
    end

Direct file uploads

To securely handle large files without routing all the data through our core API servers, we use a signed URL approach. This allows your application to upload files directly to our cloud storage providers.

  1. 1

    Request a signed upload URL

    First, you need to ask the API for a secure, temporary URL where you can upload your file.

    Make a request to the upload URL endpoint:
    POST /v1/documentation/{organization_id}/{documentation_id}/file-resources/upload-url

    The API will return a unique, time-limited URL specifically generated for your file.

  2. 2

    Upload your file

    Using the signed URL provided in the previous step, upload your file directly to the storage provider. This is typically done using an HTTP PUT request with the file's raw binary data.

  3. 3

    Finalize the upload

    Once the file has been successfully uploaded to the signed URL, you must tell the API that the process is complete so the file can be registered in your documentation project.

    Make a request to the finalize endpoint:
    POST /v1/documentation/{organization_id}/{documentation_id}/file-resources/finalize

Signed URLs are temporary and grant write access to your storage bucket. Never expose them publicly or log them in plain text. Generate them on demand and use them immediately.

Importing assets from a URL

If your images, videos, or documents are already hosted online (for example, on a public CDN or another server), you don't need to download and re-upload them. You can instruct the API to import them directly.

To import an asset, use the import endpoint:
POST /v1/documentation/{organization_id}/{documentation_id}/asset/import

Pass the public URL of the asset in your request payload. The system will fetch the file and attach it to your documentation project automatically.

Asset imports are generally faster than direct uploads because they happen server-to-server. Ensure the URL you provide is publicly accessible and does not require authentication.

Managing existing assets

Once your files are uploaded or imported, you can manage their metadata and lifecycle through the API. The system provides standard endpoints to retrieve, update, and delete assets, as well as serve the raw file content directly to users.

Endpoint reference summary

Here is a quick reference of the endpoints used for file and asset management:

ActionMethodEndpoint
Request Upload URLPOST/v1/documentation/{organization_id}/{documentation_id}/file-resources/upload-url
Finalize UploadPOST/v1/documentation/{organization_id}/{documentation_id}/file-resources/finalize
Import AssetPOST/v1/documentation/{organization_id}/{documentation_id}/asset/import
Upload AssetPOST/v1/documentation/{organization_id}/{documentation_id}/asset
Get All AssetsGET/v1/documentation/{organization_id}/{documentation_id}/asset
Get Asset by IDGET/v1/documentation/{organization_id}/{documentation_id}/asset/{asset_id}
Update Asset MetadataPUT/v1/documentation/{organization_id}/{documentation_id}/asset/{asset_id}
Delete AssetDELETE/v1/documentation/{organization_id}/{documentation_id}/asset/{asset_id}
Serve Asset FileGET/v1/documentation/{organization_id}/{documentation_id}/asset/{asset_id}/file
Why do I need organization_id and documentation_id?

Every file and asset in the system is scoped to a specific documentation project within an organization. Providing the {organization_id} and {documentation_id} in the URL path ensures your files are securely isolated and organized correctly.

What happens if I don't finalize a direct upload?

If you upload a file to the signed URL but forget to call the finalize endpoint, the file will exist in temporary cloud storage but will not appear in your documentation project. Temporary files are periodically cleaned up by the system.