Skip to content

File APIs

You can use File APIs to remotely send and upload files to your Workspace storage and insert them into any of your table within the database. The default root folder for all user files uploaded by this APIs are set to 'drive/'.

GET /file/

Returns a list of files and folders that match the given path. The path should include root folder 'drive/' and it can be expressed using a regular expression.

import requests
import json

api_token = "Issued_API_TOKEN"
search_path = "drive/file/path"
api_url = f"https://{your-engine-url}/api/v1/file/?search_path={search_path}"

header = {
    "Authorization": f"Bearer {api_token}"
}

r = requests.get(api_url, headers=header)

r.raise_for_status()
return_json = r.json()
curl -X 'GET' \
  'https://{your-engine-url}/api/v1/file/?search_path={search_path}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN' \
  -H 'Content-Type: application/json'

POST /file/

To upload a file to the drive/ directory in the Workspace, use the following methods to send the file. When the query param 'dir={dir}' is added to the URL, the file will be uploaded to the drive/{dir}/.

import requests
import json

api_token = "Issued_API_TOKEN"
api_url = "https://{your-engine-url}/api/v1/file/"
header = {
    "Authorization": f"Bearer {api_token}"
}
files = {'file': open('Data File Path', 'rb')}

r = requests.post(api_url, files=files, headers=header)

r.raise_for_status()
return_json = r.json()
curl -X 'POST' \
  'https://{your-engine-url}/api/v1/file/' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@Data File Path;type=file_type/Data File Type'

If "db_commit" is set to True and "table_name" and "column_name" are specified, the given file is sent to Workspace storage and the file path is inserted into the specified column of the specified table.

import requests
import json

api_token = "Issued_API_TOKEN"
base_url = "https://{your-engine-url}/api/v1/file/"
table_name = "Table Name"
column_name = "Column Name"
db_commit = True 

api_url = f"{base_url}?db_commit={db_commit}&table_name={table_name}&column_name={column_name}"
header = {
    "Authorization": f"Bearer {api_token}"
}
files = {'file': open('Data File Path', 'rb')}

r = requests.post(api_url, files=files, headers=header)

r.raise_for_status()
return_json = r.json()
curl -X 'POST' \
  'https://{your-engine-url}/api/v1/file/?db_commit={db_commit}&table_name={table_name}&column_name={column_name}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@Data File Path;type=file_type/Data File Type'

FAQ

  • In order to use a file within the Jupyter workspace, you must put '/'home/jovyan' in front of the path.

DELETE /file/

To delete a file from the drive/ directory in the Workspace, use the following method.

import requests
import json

api_token = "Issued_API_TOKEN"
file_path = "drive/file/path"
api_url = f"https://{your-engine-url}/api/v1/file/?file_path={file_path}'

header = {
    "Authorization": f"Bearer {api_token}"
}

r = requests.delete(api_url, headers=header)

r.raise_for_status()
return_json = r.json()
curl -X 'DELETE' \
  'https://{your-engine-url}/api/v1/file/?file_path={file_path}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN' \
  -H 'Content-Type: application/json'

If "db_commit" is set to True and "table_name" and "column_name" are specified, the given file is deleted from Workspace storage, and all rows in the table with the same value as the given file path in the specified column will be deleted.

import requests
import json

api_token = "Issued_API_TOKEN"
base_url = "https://{your-engine-url}/api/v1/file/"
db_commit = True 
file_path = "drive/file/path"
table_name = "Table Name"
column_name = "Column Name"

api_url = f"{base_url}?db_commit={db_commit}&file_path={file_path}&table_name={table_name}&column_name={column_name}"

header = {
    "Authorization": f"Bearer {api_token}"
}

r = requests.delete(api_url, headers=header)

r.raise_for_status()
return_json = r.json()
curl -X 'DELETE' \
  'https://{your-engine-url}/api/v1/file/?db_commit={db_commit}&file_path={file_path}&table_name={table_name}&column_name={column_name}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer Issued_API_TOKEN' \
  -H 'Content-Type: application/json'

Last update: 2024-04-04