5. Upload Files
POST
/documentClassification/deleteFiles
This endpoint enables users to upload files to a specific document classification process.
If a batchId
is provided in the request, the uploaded files will be added to that existing batch. If batchId
is omitted, a new batch will be automatically created for the files under the specified classificationId
.
Files must be uploaded using the multipart/form-data
content type, which is required for binary file uploads such as PDFs, images, or scanned documents. Ensure the classificationId
is valid, and that any provided batchId
already exists within the classification context.
Server URL
https://api.extracta.ai/api/v1
Headers
Content-Type
multipart/form-data
Authorization
Bearer <token>
Body
classificationId
string
true
Unique identifier for the extraction.
batchId
string
false
The ID of the batch to add files to.
files
multipart
true
For a seamless classification process, please ensure your documents are in one of our supported formats. Check our Supported File Types page for a list of all formats we currently accept and additional details to prepare your files accordingly.
Code Example
Note for PHP Users: Currently, the /uploadFiles
endpoint supports uploading only one file per request. Please ensure you submit individual requests for each file you need to upload.
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');
async function uploadFilesToClassification(token, classificationId, files, batchId = null) {
const url = "https://api.extracta.ai/api/v1/documentClassification/uploadFiles";
let formData = new FormData();
formData.append('classificationId', classificationId);
if (batchId) {
formData.append('batchId', batchId);
}
files.forEach(file => {
formData.append('files', fs.createReadStream(file));
});
try {
const response = await axios.post(url, formData, {
headers: {
...formData.getHeaders(),
'Authorization': `Bearer ${token}`
}
});
return response.data;
} catch (error) {
throw error.response ? error.response.data : new Error('An unknown error occurred');
}
}
async function main() {
const token = 'apiKey';
const classificationId = 'classificationId';
const files = ['test_1.pdf', 'test_2.jpg'];
const batchId = null; // or specify an existing batchId if needed
try {
const response = await uploadFilesToClassification(token, classificationId, files, batchId);
console.log("Upload Response:", response);
} catch (error) {
console.error("Failed to upload files:", error);
}
}
main();
Responses
{
"status": "uploaded",
"classificationId": "classificationId",
"batchId": "batchId",
"files": [
{
"fileId": "fileId",
"fileName": "file.pdf",
"numberOfPages": 1,
"url": "fileUrl"
}
]
}
Last updated
Was this helpful?