Chunk up a large file then upload to Anaplan
Upload a file in chunks
For large files, split the file into chunks and upload each chunk separately. The first chunk might represent the entire file, or the file might consist of multiple chunks. If the file is larger than 1 MB, PUT each chunk to the server by streaming the chunk as an octet stream.
Use the Content-Type: application/octet-stream header.
Endpoint
PUT /workspaces/{workspaceId}/models/{modelId}/files/{fileId}/chunks/{chunkId}
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
fileId | The file ID. |
chunkId | The chunk ID of the file. For example, the first chunk can use 0. |
Expected response
A successful chunk upload returns:
204 No Content
Split a file into chunks
You can split a file into chunks before upload by using a shell command such as split.
Syntax: split -b [number of bytes] [path and filename] [prefix for output files]
Example: split -b 15360 ArchivedOpportunities.csv chunk-
This command splits ArchivedOpportunities.csv into chunk files that use chunk- as the output file prefix.
Chunk size guidance
Specify a chunk size no larger than 50 MB of uncompressed data.
Use no more than 1,000 chunks per file.
For larger chunks, compressing the chunks can reduce upload time.
Compressed chunks
You can compress chunk files before upload.
For example, this shell command compresses all files in the current folder and folders below it if the files do not already have the .gz extension: find . -type f ! -name '*.gz' -exec gzip "{}" \;
If you upload compressed chunks, use this header instead of Content-Type: application/octet-stream:
Content-Type: application/x-gzip
The chunks must be compressed with the gzip format.
Complete the upload
After uploading chunks with chunkCount set to -1, mark the upload as complete.
Endpoint
POST /workspaces/{workspaceId}/models/{modelId}/files/{fileId}/complete
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
fileId | The file ID. |
Request format
Use Content-Type: application/json.
The request body includes file metadata such as:
{
"id": "113000000008",
"name": "Tests.txt",
"chunkCount": 1,
"firstDataRow": 2,
"headerRow": 1
}
Expected response
A successful completion request returns a JSON response with the file metadata.
Download files
You can download files that were uploaded, or download files after carrying out an export.
To download a file in chunks:
- Get the list of files for the model.
- Identify the file you want to download.
- Get the chunks in the file.
- Download the data in each chunk.
Get the list of files
Use the file list endpoint to get import and export files for a model.
Endpoint
GET /workspaces/{workspaceId}/models/{modelId}/files
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
Expected response
A successful response returns JSON with a files array.
Each file object can include values such as id, name, chunkCount, encoding, firstDataRow, format, headerRow, and separator.
Get the chunks in a file
To download a file in chunks, first get the ID of each chunk.
Endpoint
GET /workspaces/{workspaceId}/models/{modelId}/files/{fileId}/chunks
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
fileId | The file ID. |
Expected response
A successful response returns JSON with a chunks array.
Example chunk objects:
{
"id": "0",
"name": "Chunk 0"
}
Get the data in a chunk
After you know the chunk ID, download the data for that chunk.
Endpoint
GET /workspaces/{workspaceId}/models/{modelId}/files/{fileId}/chunks/{chunkId}
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
fileId | The file ID. |
chunkId | The chunk ID of the file. |
Delete files
You can delete files that you uploaded through the API.
Deleting a file removes only private content. Default content and the import data source model object remain.
Endpoint
DELETE /workspaces/{workspaceId}/models/{modelId}/files/{fileId}
Required parameters
| Parameter | Description |
workspaceId | The workspace ID. |
modelId | The model ID. |
fileId | The file ID. |