Skip to main content

Download File

Download a file from your storage. You can get the direct download URL or download the file directly.

Endpoint

GET /files/{fileId}

Path Parameters

ParameterTypeRequiredDescription
fileIdstringYesThe ID of the file to download

Query Parameters

ParameterTypeRequiredDescription
downloadbooleanNoForce download instead of redirect (default: false)
expiresnumberNoURL expiration time in seconds (max: 3600)

Example Request

curl -X GET "https://api.astracollab.app/v1/files/file_1234567890abcdef" \
  -H "Authorization: Bearer your-api-key-here"

Response

{
  "success": true,
  "data": {
    "file": {
      "id": "file_1234567890abcdef",
      "name": "example.jpg",
      "size": 1024000,
      "type": "image/jpeg",
      "url": "https://storage.astracollab.app/files/file_1234567890abcdef",
      "downloadUrl": "https://storage.astracollab.app/files/file_1234567890abcdef?download=true&expires=3600",
      "folderId": "folder_123",
      "uploadedAt": "2024-01-15T10:30:00Z",
      "updatedAt": "2024-01-15T10:30:00Z",
      "metadata": {
        "width": 1920,
        "height": 1080
      }
    }
  }
}

Direct Download

To download the file directly (instead of getting metadata):
curl -X GET "https://api.astracollab.app/v1/files/file_1234567890abcdef?download=true" \
  -H "Authorization: Bearer your-api-key-here" \
  --output example.jpg

Presigned URLs

For secure, time-limited access to files:
curl -X GET "https://api.astracollab.app/v1/files/file_1234567890abcdef?expires=3600" \
  -H "Authorization: Bearer your-api-key-here"
This returns a presigned URL that’s valid for 1 hour and can be shared without authentication.

Error Responses

File Not Found

{
  "success": false,
  "error": {
    "code": "FILE_NOT_FOUND",
    "message": "File with ID 'file_1234567890abcdef' not found"
  }
}

Access Denied

{
  "success": false,
  "error": {
    "code": "ACCESS_DENIED",
    "message": "You don't have permission to access this file"
  }
}

URL Expired

{
  "success": false,
  "error": {
    "code": "URL_EXPIRED",
    "message": "Download URL has expired"
  }
}

SDK Examples

curl -X GET "https://api.astracollab.app/v1/files/file_1234567890abcdef" \
  -H "Authorization: Bearer your-api-key-here"

Browser Download

For browser-based downloads, you can use the download URL directly:
const downloadFile = async (fileId) => {
  const response = await fetch(`https://api.astracollab.app/v1/files/${fileId}?download=true`, {
    headers: {
      'Authorization': 'Bearer your-api-key-here'
    }
  });
  
  const blob = await response.blob();
  const url = window.URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'filename.jpg';
  a.click();
  window.URL.revokeObjectURL(url);
};

Streaming Downloads

For large files, you can stream the download:
const streamDownload = async (fileId) => {
  const response = await fetch(`https://api.astracollab.app/v1/files/${fileId}`, {
    headers: {
      'Authorization': 'Bearer your-api-key-here'
    }
  });

  const reader = response.body.getReader();
  const chunks = [];

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    chunks.push(value);
  }

  const blob = new Blob(chunks);
  return blob;
};