Upload files to Formant Cloud

This guide will show you how to upload files to Formant. Files can be uploaded via the web app, the Cloud SDK , or File API. These files can then be retrieved via the File API.

Web app

You can use the Cloud Files menu to upload and manage your files in Formant.

To upload files via the web app:

  1. Go to https://app.formant.io .
  2. Navigate to Settings >> Cloud Files and upload your file.

Formant will accept the file and return a File ID. You can now use this File ID elsewhere in Formant. You can also use it with the File API.

2816

Upload or manage Cloud Files from within the Formant web app.

File API commands

List Cloud files

import requests

url = "https://api.formant.io/v1/admin/files"

headers = {
    "Authorization": "Bearer eyJraWQiOiJRWFY0Rk5HenlpdGh..."
}

response = requests.post(url, headers=headers)

print(response.text)

"""
Response is of the form:
{
  "items": [
    {
      "id": "0d349986-3be8-4920-9bb1-60ec7b437320",
      "createdAt": "2023-01-19T12:42:44.352Z",
      "updatedAt": "2023-01-19T12:42:44.352Z",
      "tags": {},
      "name": "test.txt",
      "organizationId": "0d29f656-cc1c-4b9e-baad-199cfa1fcced",
      "userId": "d4a63e17-7f42-42c2-b427-badc0d093c26",
      "fileId": "433f4fa1-6266-4d81-8426-c7e4d4fa3b23",
      "fileSize": 11
    },
    {
      "id": "ef3f1d06-2586-4846-b1f0-a0d700d194bb",
      "createdAt": "2023-01-19T21:49:49.001Z",
      "updatedAt": "2023-01-19T21:49:49.001Z",
      "tags": {},
      "name": "empty.zip",
      "organizationId": "0d29f656-cc1c-4b9e-baad-199cfa1fcced",
      "userId": "7fa1286e-ffa7-453b-b163-308b3b28654a",
      "fileId": "ee743c61-038a-4157-90e7-92e658d6ac09",
      "fileSize": 174
    }
  ]
}
"""

Retrieve file by ID

Once you have a file ID, pass it into the File API to retrieve it. Example:

import requests

ID = "0d349986-3be8-4920-9bb1-60ec7b437320"

url = f'https://api.formant.io/v1/admin/files/{ID}' 

headers = {
    "Authorization": "Bearer eyJraWQiOiJRWFY0Rk5HenlpdGh..."
}

response = requests.get(url, headers=headers)

print(response.text)

"""
Response is of the form:
{
  "id": "0d349986-3be8-4920-9bb1-60ec7b437320",
  "createdAt": "2023-01-19T12:42:44.352Z",
  "updatedAt": "2023-01-19T12:42:44.352Z",
  "tags": {},
  "name": "test.txt",
  "organizationId": "0d29f656-cc1c-4b9e-baad-199cfa1fcced",
  "userId": "d4a63e17-7f42-42c2-b427-badc0d093c26",
  "fileId": "433f4fa1-6266-4d81-8426-c7e4d4fa3b23",
  "fileSize": 11
}
"""

Get download URL by ID

import requests

ID = "0d349986-3be8-4920-9bb1-60ec7b437320"

url = f'https://api.formant.io/v1/admin/files/{ID}/url' 

headers = {
    "Authorization": "Bearer eyJraWQiOiJRWFY0Rk5HenlpdGh..."
}

response = requests.get(url, headers=headers)

print(response.text)

"""
Response is of the form:
https://telemetry-prod-usw2-file-storage-service.s3.amazonaws.com/files/0d29f656-cc1c-4b9...
"""

Rename or add tags

import requests

ID = "d3640568-26d7-4cbd-8a45-2b43b63de37c"

url = f'https://api.formant.io/v1/admin/files/{ID}' 

payload = {
    "name": "TF_renamed.yaml",
    "tags": {
        "env": "test"
    }}

headers = {
    "Authorization": "Bearer eyJraWQiOiJRWFY0Rk5HenlpdGh..."
}

response = requests.patch(url, json=payload, headers=headers)

print(response.text)

"""
Response is of the form:
{
  "id": "d3640568-26d7-4cbd-8a45-2b43b63de37c",
  "createdAt": "2023-01-23T16:42:46.119Z",
  "updatedAt": "2023-01-23T16:45:26.949Z",
  "tags": {
    "env": "test"
  },
  "name": "TF_renamed.yaml",
  "organizationId": "0d29f656-cc1c-4b9e-baad-199cfa1fcced",
  "userId": "120df898-7a5a-4706-b431-a29598a8eccb",
  "fileId": "88afe8c7-0d4f-4d82-91ef-a3e2f325cd1b",
  "fileSize": 583
}
"""