Laravel + Transloadit
Send a validated Laravel upload to a fixed Transloadit Template with the official PHP SDK and server-side credentials.
Executable recipe
Build the integration
This controller validates an uploaded file, starts a fixed Template through the PHP SDK, and returns its Assembly ID or a sanitized error.
- Install the PHP SDK and create a Transloadit Template.
- Add the three environment values and map them in config/services.php.
- Register a POST route for the controller and submit a multipart file field named file.
Install
composer require transloadit/php-sdkconfig/services.php
'transloadit' => [
'key' => env('TRANSLOADIT_KEY'),
'secret' => env('TRANSLOADIT_SECRET'),
'template_id' => env('TRANSLOADIT_TEMPLATE_ID'),
],app/Http/Controllers/MediaController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use transloadit\Transloadit;
class MediaController extends Controller
{
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'file' => ['required', 'file', 'max:102400'],
]);
$transloadit = new Transloadit([
'key' => config('services.transloadit.key'),
'secret' => config('services.transloadit.secret'),
]);
$assembly = $transloadit->createAssembly([
'files' => [$validated['file']->getRealPath()],
'params' => [
'template_id' => config('services.transloadit.template_id'),
],
]);
$hasSdkError = (bool) $assembly->error();
if ($hasSdkError || !isset($assembly->data['assembly_id'])) {
// Provider responses may contain secrets; log only a fixed failure category.
Log::warning('Transloadit Assembly creation failed', [
'reason' => $hasSdkError ? 'sdk_error' : 'missing_assembly_id',
]);
return response()->json(['error' => 'Could not start media processing'], 502);
}
return response()->json(['assembly_id' => $assembly->data['assembly_id']], 202);
}
}Authentication
- Store the Transloadit Auth Key, Auth Secret, and Template ID in Laravel environment configuration and read them through config/services.php.
- The official PHP SDK signs Assembly requests automatically when both the key and secret are supplied.
- Validate uploaded files and enforce your application’s authorization before sending a server-side file to Transloadit.
Limitations and operational notes
- createAssembly starts the Assembly but does not make long processing synchronous. Return the Assembly ID and use webhooks or status retrieval for completion.
- The example uploads through the Laravel server. For large browser uploads, use Uppy to send bytes directly to Transloadit and let Laravel only authorize signatures.
- Laravel’s file validation and your Transloadit Template limits are separate controls; configure both for the same product policy.
More integrations