Skip to main content
GET
/
v1
/
files
/
{file_id}
/
content
Retrieve File Content
curl --request GET \
  --url https://api.gravixlayer.com/v1/files/{file_id}/content \
  --header 'Authorization: Bearer <token>'
Overview The Retrieve File Content API allows you to download the actual content of files stored in your Gravix Layer organization. Use this endpoint to access file data for processing, analysis, or local storage. Key Features
  • Direct content access with binary and text support
  • Streaming downloads for large files
  • Format preservation maintaining original file structure
  • Range requests for partial downloads
  • Content-Type headers for proper handling
Common Use Cases
Download files for local processing:
# Download training data for analysis
content = client.files.content("file-abc123")

# Process JSONL training data
import json
for line in content.decode().split('\n'):
    if line.strip():
        data = json.loads(line)
        process_training_example(data)
Path Parameters
ParameterTypeRequiredDescription
file_idstringYesThe ID of the file to download

Example Request

curl https://api.gravixlayer.com/v1/files/file-abc123/content \
  -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
  -o downloaded_file.jsonl

Response

The response contains the raw file content as binary data. The Content-Type header will match the original file’s MIME type.

Response Headers

HeaderDescription
Content-TypeMIME type of the file
Content-LengthSize of the file in bytes
Content-DispositionSuggests filename for download

Error Responses

Status CodeError TypeDescription
404file_not_foundFile with the specified ID does not exist
401authentication_errorInvalid or missing API key
403permission_deniedFile belongs to a different organization
410file_deletedFile has been deleted or expired

Use Cases

Download file and process its content:
import json

def download_and_process_jsonl(file_id):
    """Download JSONL file and process each line"""
    # Download content
    content = client.files.content(file_id)
    
    # Process JSONL content
    lines = content.decode('utf-8').strip().split('\n')
    
    processed_data = []
    for line in lines:
        if line.strip():
            data = json.loads(line)
            processed_data.append(data)
    
    return processed_data

# Usage
data = download_and_process_jsonl("file-abc123")
print(f"Processed {len(data)} records")

Best Practices

Large file downloads may take time and consume bandwidth. Consider using streaming downloads for files over 10MB.

Error Handling

def safe_file_download(file_id, max_retries=3):
    """Download file with error handling and retries"""
    
    for attempt in range(max_retries):
        try:
            content = client.files.content(file_id)
            return content
            
        except requests.exceptions.RequestException as e:
            if attempt < max_retries - 1:
                wait_time = 2 ** attempt
                print(f"⏳ Download failed, retrying in {wait_time}s... (attempt {attempt + 1})")
                time.sleep(wait_time)
            else:
                print(f"❌ Download failed after {max_retries} attempts: {e}")
                raise
        
        except Exception as e:
            print(f"❌ Unexpected error: {e}")
            raise
    
    return None

Authorizations

Authorization
string
header
required

API key authentication. Get your API key from the Gravix Layer Dashboard.

Path Parameters

file_id
string
required

The ID of the file to download

Response

200

File content