| Home | Getting Started | Core Concepts | Helpers | Extensions | Repo |
The Spaces helper provides an interface for managing file storage using DigitalOcean Spaces or Amazon S3.
Configure in your .env file:
SPACES_KEY=your_access_key
SPACES_SECRET=your_secret_key
SPACES_REGION=nyc3
SPACES_BUCKET=your-bucket
SPACES_ENDPOINT=https://nyc3.digitaloceanspaces.com
// Upload file from path
$url = tiny::spaces()->upload(
'uploads/images',
'/path/to/local/file.jpg'
);
// Upload from content
$url = tiny::spaces()->uploadContent(
'uploads/files/doc.pdf',
$fileContent,
[
'ContentType' => 'application/pdf',
'ACL' => 'public-read'
]
);
// Upload with custom options
$url = tiny::spaces()->upload('path/to/file.jpg', $file, [
'ACL' => 'private',
'CacheControl' => 'max-age=31536000',
'Metadata' => ['user_id' => '123']
]);
// Get file
$content = tiny::spaces()->get('path/to/file.jpg');
// Get with expiring URL
$url = tiny::spaces()->signedUrl('private/file.pdf', '+2 hours');
// Download to local path
tiny::spaces()->download('remote/file.zip', '/local/path/file.zip');
// Check if file exists
if (tiny::spaces()->exists('path/to/file.jpg')) {
// File exists
}
// Delete file
tiny::spaces()->delete('path/to/file.jpg');
// Copy file
tiny::spaces()->copy(
'source/file.jpg',
'destination/file.jpg'
);
// Move/rename file
tiny::spaces()->move(
'old/path/file.jpg',
'new/path/file.jpg'
);
// List files
$files = tiny::spaces()->list('uploads/images/');
// List with prefix
$files = tiny::spaces()->list('uploads/', [
'prefix' => 'images/',
'maxKeys' => 100
]);
// Delete directory
tiny::spaces()->deleteDir('old/uploads/');
// Make file public
tiny::spaces()->setAcl(
'path/to/file.jpg',
'public-read'
);
// Make file private
tiny::spaces()->setAcl(
'path/to/file.jpg',
'private'
);
// Get file info
$info = tiny::spaces()->info('path/to/file.jpg');
// Update metadata
tiny::spaces()->updateMetadata('path/to/file.jpg', [
'ContentType' => 'image/jpeg',
'CacheControl' => 'max-age=86400'
]);