Skip to content

Cloud Storage (Files)

Suppa API integrates with Google Cloud Storage (GCS) for file management. The process involves getting a pre-signed upload URL and then "attaching" the uploaded file to a specific entity record.

Uploading a File

The unified upload API simplifies the process by combining file upload and attachment into a single request.

Endpoint: POST /core/files/upload

Request Body (form-data)

The request should be sent as multipart/form-data with two primary fields:

  1. meta (String/JSON): A JSON string containing the attachment metadata.
  2. file (File): The binary content of the file.

Meta Field Structure

FieldTypeRequiredDescription
entityNamestringtrueEntity type (e.g., Products, Receipts).
recordIdnumbertrueThe ID of the specific record to attach the file to.
entityFieldNamestringtrueThe field name in the entity where the file should be attached.

Response Body

The response is an object containing arrays for successful and failed uploads, along with a summary.

json
{
  "success": [
    {
      "id": 123,
      "fileName": "document.pdf",
      "downloadUrl": "https://storage.googleapis.com/...",
      "createdAt": "2023-10-27T10:00:00Z"
    }
  ],
  "errors": [],
  "summary": {
    "total": 1,
    "successful": 1,
    "failed": 0
  }
}

Success Object Fields

FieldTypeDescription
idnumberID of the created record in the files table.
fileNamestringThe name of the uploaded file.
downloadUrlstringDirect URL to download the file.
createdAtstringISO timestamp of creation.

Downloading a File

Directly download file content using its unique identifier.

Endpoint: GET /core/files/download

Query Parameters

ParameterTypeRequiredDescription
fileIdstringtrueThe unique identifier of the file to download.
fileTypestringtrueThe type of file (e.g., file, preview).

Response

The response body contains the binary content of the file.

Remove Files

Delete one or more files from the system.

Endpoint: POST /core/data/Files/remove

Request Body:

json
{
  "conditions": {
    "operator": "and",
    "filters": [
      {
        "field": "id",
        "comparator": "in",
        "value": [10, 11]
      }
    ]
  }
}