Create Upload
This endpoint allows you to create a new upload in the system.
API Endpoint
POST /v2/{team_id}/project/{project_id}/upload
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | No | The name of the upload |
| file | file | Yes | The file to upload, adding multiple file fields will create an upload with one task for every upload |
| projectId | string | Yes | The project ID to associate with |
| meta | array | No | Additional metadata for the upload, array of name, value objects |
Example Request
- cURL
- Typescript
- Python
- C#
curl -X POST \
'https://api.send.ai/v2/team_123456/project/proj_123456/upload' \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@document.pdf" \
-F "name=Important Document" \
-F 'meta=[{"name":"category", "value":"invoice"},{"name":"department", "value":"finance"}]'
interface UploadRequest {
name: string;
projectId: string;
meta?: {name: string, value: string}[];
}
const createUpload = async (file: File, data: UploadRequest): Promise<any> => {
const formData = new FormData();
formData.append('file', file);
formData.append('name', data.name);
formData.append('projectId', data.projectId);
if (data.meta) {
formData.append('meta', JSON.stringify(data.meta));
}
const response = await fetch('https://api.send.ai/api/v1/uploads', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
});
if (!response.ok) {
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
}
return response.json();
};
// Example usage
const file = new File(['file content'], 'document.pdf', { type: 'application/pdf' });
createUpload(file, {
name: 'Important Document',
projectId: 'proj_123456',
meta: [
{name: 'category', value: 'invoice'},
{name: 'department', value: 'finance'}
]
}).then(result => console.log(result));
import requests
import json
def create_upload(file_path, name, project_id, meta=None):
url = 'https://api.send.ai/api/v1/uploads'
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
data = {
'name': name,
'projectId': project_id
}
files = {
'file': open(file_path, 'rb')
}
if meta:
data['meta'] = json.dumps(meta)
response = requests.post(
url,
headers=headers,
data=data,
files=files
)
response.raise_for_status() # Raise exception for 4XX/5XX responses
return response.json()
# Example usage
result = create_upload(
file_path='document.pdf',
name='Important Document',
project_id='proj_123456',
meta=[
{'name': 'category', 'value': 'invoice'},
{'name': 'department', 'value': 'finance'}
]
)
print(result)
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
public class UploadService
{
private readonly HttpClient _client;
private readonly string _apiKey;
public UploadService(string apiKey)
{
_client = new HttpClient();
_client.BaseAddress = new Uri("https://api.send.ai/");
_apiKey = apiKey;
}
public class MetaItem
{
public string Name { get; set; }
public string Value { get; set; }
}
public async Task<object> CreateUploadAsync(
string filePath,
string name,
string projectId,
List<MetaItem> meta = null)
{
using var formData = new MultipartFormDataContent();
// Add file content
var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filePath));
var fileName = System.IO.Path.GetFileName(filePath);
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
formData.Add(fileContent, "file", fileName);
// Add other form fields
formData.Add(new StringContent(name), "name");
formData.Add(new StringContent(projectId), "projectId");
// Add metadata if provided
if (meta != null)
{
var metaJson = JsonSerializer.Serialize(meta);
formData.Add(new StringContent(metaJson), "meta");
}
// Set authorization header
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
// Send request
var response = await _client.PostAsync("api/v1/uploads", formData);
// Ensure success
response.EnsureSuccessStatusCode();
// Parse and return response
var jsonResponse = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<object>(jsonResponse);
}
}
// Example usage
public class Program
{
public static async Task Main()
{
var uploadService = new UploadService("YOUR_API_KEY");
var meta = new List<UploadService.MetaItem>
{
new UploadService.MetaItem { Name = "category", Value = "invoice" },
new UploadService.MetaItem { Name = "department", Value = "finance" }
};
try
{
var result = await uploadService.CreateUploadAsync(
"document.pdf",
"Important Document",
"proj_123456",
meta
);
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
Response
{
"id": "upl_abc123",
"name": "Important Document",
"projectId": "proj_123456",
"status": "processing",
"fileType": "pdf",
"fileSize": 1024567,
"createdAt": "2023-06-15T10:30:00Z",
"updatedAt": "2023-06-15T10:30:00Z"
}
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| id | string | Unique identifier for the upload |
| name | string | The name of the upload |
| projectId | string | The project ID associated with the upload |
| status | string | Current status of the upload |
| fileType | string | The type of the uploaded file |
| fileSize | number | Size of the file in bytes |
| createdAt | string | ISO timestamp of when the upload was created |
| updatedAt | string | ISO timestamp of when the upload was last updated |
Error Codes
| Status Code | Description |
|---|---|
| 400 | Bad request, check your request parameters |
| 401 | Unauthorized, check your API key |
| 403 | Forbidden, you don't have access to this project |
| 413 | Payload too large, file exceeds size limit |
| 500 | Server error, please try again later |