Skip to content

Documentation

PHP SDK: S3: storing files

Select a configured connection with $ctx->storage('media'). The platform checks the connection code and permissions. For external S3 storage, transfer and processing time count toward usage; the file size does not count as platform storage.

Complete SDK reference

Methods

putFromUrl

putFromUrl(string $url, ?string $key = null, ?string $mime = null): StoredFile

Download a file from a site and upload it to the selected S3 connection.

$file = $ctx->storage('media')->putFromUrl($ctx->param('image_url'), 'products/A-1.jpg');
$ctx->emit(['sku' => 'A-1', 'image_key' => $file->key], 'A-1');

Result and notes. Returns StoredFile. key and mime are optional. Without key, the name is generated automatically. During a trial run, no upload occurs and dryRun=true.

put

put(string $key, string $content, string $mime = 'text/plain'): StoredFile

Write a small text file, such as a report, JSON, or CSV.

$content = json_encode(['count' => 12], JSON_UNESCAPED_UNICODE);
$file = $ctx->storage('media')->put('reports/count.json', $content, 'application/json');

Result and notes. Returns StoredFile. Text is limited to 1 MB. Use putFromUrl() for larger files and images.

exists

exists(string $key): bool

Check whether an object exists under a key.

$exists = $ctx->storage('media')->exists('products/A-1.jpg');

Result and notes. Returns a boolean. Existence at the time of checking does not guarantee that the object will remain unchanged before the next request.

url

url(string $key, int $ttlSeconds = 3600): string

Get a temporary signed link to an object.

$downloadUrl = $ctx->storage('media')->url('products/A-1.jpg', 3600);

Result and notes. Returns a string. ttlSeconds is in seconds and defaults to one hour. Keep the key as the permanent identifier; a temporary URL expires.