code
DveloxSoft Bucket Developer integration guides

Upload Files

Upload files to a container using either a simple multipart POST for files under 500 MB, or chunked uploads for larger files. Both methods require a valid container slug and authentication.

When to use each method

Simple upload

Files smaller than 500 MB. One multipart POST, server stores the file directly.

Chunked upload

Files 500 MB or larger. Split into 10 MB chunks. Frontend sends batches of up to 5 chunks per request.

Simple upload

Send a multipart/form-data request to POST /files/:containerSlug/*path. The server saves the file at the requested path.

typescript
const formData = new FormData();
formData.append('file', file);

const response = await fetch(
  `https://bucket.dveloxsoft.com/api/files/${containerSlug}/${encodeURIComponent(path)}`,
  {
    method: 'POST',
    headers: {
      'Authorization': 'ApiKey <api_key>'
    },
    body: formData
  }
);

if (!response.ok) {
  const error = await response.json();
  throw new Error(error.message || 'Upload failed');
}

const result = await response.json();
console.log('Uploaded to:', result.path, result.size, 'bytes');

Chunked upload

For large files, generate a stable fileId, slice the file into 10 MB chunks, and send them in batches to POST /files/:containerSlug/chunked. The server assembles the file once all chunks arrive.

typescript
const CHUNK_SIZE = 10 * 1024 * 1024; // 10 MB
const fileId = crypto.randomUUID();
const totalChunks = Math.ceil(file.size / CHUNK_SIZE);

for (let i = 0; i < totalChunks; i += 5) {
  const batchIndices: number[] = [];
  const batchChunks: Blob[] = [];

  for (let j = i; j < Math.min(i + 5, totalChunks); j++) {
    const start = j * CHUNK_SIZE;
    const end = Math.min(start + CHUNK_SIZE, file.size);
    batchIndices.push(j);
    batchChunks.push(file.slice(start, end));
  }

  const formData = new FormData();
  batchChunks.forEach((chunk, idx) => {
    formData.append('files', chunk, `${fileId}-${batchIndices[idx]}`);
  });
  formData.append('fileId', fileId);
  formData.append('totalChunks', String(totalChunks));
  formData.append('fileName', file.name);
  formData.append('filePath', path);
  formData.append('chunkIndices', batchIndices.join(','));

  const response = await fetch(
    `https://bucket.dveloxsoft.com/api/files/${containerSlug}/chunked`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'ApiKey <api_key>'
      },
      body: formData
    }
  );

  const data = await response.json();
  console.log('Chunk batch progress:', data);
}

Track progress with events

Use the Fetch API with reportProgress: true to receive upload progress events. Map progress events to a percentage and response events to the final result.

typescript
const response = await fetch(
  `https://bucket.dveloxsoft.com/api/files/${containerSlug}/${path}`,
  {
    method: 'POST',
    headers: {
      'Authorization': 'ApiKey <api_key>'
    },
    body: formData,
    signal: AbortSignal.timeout(30000)
  }
);

if (!response.ok) {
  const error = await response.json();
  throw new Error(error.message || 'Upload failed');
}

const result = await response.json();
console.log('Upload complete:', result);