PHP SDK - Storage#

S3-compatible object storage: buckets, objects, folders and presigned URLs.

Buckets#

$bucket = $db->storage->createBucket(
    name: 'Avatars',
    slug: 'avatars',
    isPublic: true,
    fileSizeLimit: 5 * 1024 * 1024,                 // optional, bytes
    allowedMimeTypes: ['image/png', 'image/jpeg'],  // optional
);

$db->storage->listBuckets();
$db->storage->getBucket($bucket->data['id']);
$db->storage->deleteBucket($bucket->data['id']);
PHP

Objects#

$db->storage->listObjects($bucketId);
$db->storage->createFolder($bucketId, '2026');
$db->storage->deleteObject($objectId);
PHP

Upload#

Get a presigned URL, then PUT the file body to it:

$upload = $db->storage->signedUploadUrl(
    bucketId: $bucketId,
    objectName: 'user-1.png',
    contentLength: 2 * 1024 * 1024, // optional
);

$ch = curl_init($upload->data['url']);
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => file_get_contents('user-1.png'),
    CURLOPT_RETURNTRANSFER => true,
]);
curl_exec($ch);
curl_close($ch);
PHP

Use the signed headers returned in $upload->data when the bucket requires them.

Download#

$download = $db->storage->signedDownloadUrl($objectId);

// Public URL (no auth, public buckets only)
$url = $db->storage->publicUrl($bucketId, $objectId);
PHP

Next: Environment variables.