Skip to main content

Choosing the Right Method

Drime Cloud offers several upload methods depending on your file size:

Simple Upload (< 5 MB)

For small files, use direct upload:
const formData = new FormData();
formData.append('file', file);
formData.append('workspaceId', '0');

const response = await fetch('https://app.drime.cloud/api/v1/uploads', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer TOKEN' },
  body: formData
});

Presigned URL Upload (< 5 MB)

More performant, as it uploads directly to storage:
1

Get the presigned URL

const { url, key } = await fetch('/s3/simple/presign', {
  method: 'POST',
  body: JSON.stringify({ filename, mime, size, extension })
}).then(r => r.json());
2

Upload to S3

await fetch(url, { method: 'PUT', body: file });
3

Register the file

await fetch('/s3/entries', {
  method: 'POST',
  body: JSON.stringify({ filename: key.split('/').pop(), size, clientName })
});

Multipart Upload (≥ 5 MB)

For large files, split into 5 MB chunks:
1

Initialize

Call /s3/multipart/create to get an uploadId
2

Sign URLs

Call /s3/multipart/batch-sign-part-urls for each part
3

Upload parts

PUT each chunk to its URL, collect the ETags
4

Complete

Call /s3/multipart/complete with all ETags
5

Register

Call /s3/entries to create the file entry
If interrupted, use /s3/multipart/get-uploaded-parts to resume the upload where it left off.

Duplicate Validation

Before uploading, check if the file already exists:
const { duplicates } = await fetch('/uploads/validate', {
  method: 'POST',
  body: JSON.stringify({
    files: [{ name: 'photo.jpg', size: 1024, relativePath: '/photos' }]
  })
}).then(r => r.json());

if (duplicates.length > 0) {
  // Ask the user or auto-rename
  const { name } = await fetch('/entry/getAvailableName', {
    method: 'POST',
    body: JSON.stringify({ name: 'photo.jpg', parentId: null })
  }).then(r => r.json());
}