A simplified, Laravel-focused PHP client for the UploadThing v6 REST API.
- β
V6 API Compatible: Uses UploadThing v6
/uploadFilesendpoint - β Type-safe: Full PHP 8.1+ type declarations and strict typing
- β Laravel-focused: Designed specifically for Laravel applications
- β Environment-based configuration: Simple configuration via environment variables
- β File uploads: Upload files using presigned S3 URLs
- β Webhook verification: HMAC-SHA256 signature validation with timestamp tolerance
- β Simple API: Clean, straightforward interface
composer require hernol/uploadthing-phpSet your environment variables in your .env file:
UPLOADTHING_API_KEY=ut_sk_your_api_key_here
UPLOADTHING_BASE_URL=https://api.uploadthing.com
UPLOADTHING_API_VERSION=v6
UPLOADTHING_TIMEOUT=30
UPLOADTHING_CALLBACK_URL=https://your-app.com/webhook
UPLOADTHING_CALLBACK_SLUG=your-slug<?php
use UploadThing\Resources\Uploads;
$uploads = new Uploads();
$file = $uploads->uploadFile('/path/to/file.jpg');
if ($file) {
echo "File uploaded: {$file->name}\n";
echo "File URL: {$file->url}\n";
echo "File ID: {$file->id}\n";
}<?php
use UploadThing\Resources\Uploads;
$uploads = new Uploads();
$file = $uploads->uploadFile(
'/path/to/image.jpg',
'my-custom-name.jpg',
'image/jpeg'
);<?php
use UploadThing\Resources\Webhooks;
$webhooks = new Webhooks();
// Handle webhook from Laravel request
$event = $webhooks->handleWebhook(
$request->getContent(),
$request->headers->all(),
env('UPLOADTHING_WEBHOOK_SECRET')
);
echo "Event type: {$event->type}\n";
echo "Event data: " . json_encode($event->data) . "\n";<?php
use UploadThing\Resources\Webhooks;
$webhooks = new Webhooks();
$event = $webhooks->handleWebhookFromGlobals(
env('UPLOADTHING_WEBHOOK_SECRET')
);The client uses the UploadThing v6 /uploadFiles endpoint which:
- Prepares the upload and returns S3 presigned URL data
- Uploads the file to S3 using multipart form data
- Finalizes the upload via polling (retries up to 5 times with 1-second delays)
<?php
use UploadThing\Exceptions\ApiException;
use UploadThing\Exceptions\AuthenticationException;
use UploadThing\Exceptions\RateLimitException;
use UploadThing\Exceptions\ValidationException;
try {
$file = $uploads->uploadFile('/path/to/file.jpg');
} catch (AuthenticationException $e) {
echo "Invalid API key: " . $e->getMessage();
} catch (RateLimitException $e) {
echo "Rate limited, retry after: " . $e->getRetryAfter() . "s";
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage();
} catch (ApiException $e) {
echo "API Error: " . $e->getMessage();
echo "Error Code: " . $e->getErrorCode();
}See the examples folder for complete usage examples:
- Basic File Upload
- Upload with Custom Options
- Webhook Handling
- Webhook Handler Utility
- Webhook Verifier
- Laravel Controller Example
- Error Handling
- PHP 8.1 or higher
- Composer
- UploadThing API key
| PHP Version | Support |
|---|---|
| 8.1 | β Full support |
| 8.2 | β Full support |
| 8.3 | β Full support |
You can create a service provider to bind the resources:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use UploadThing\Resources\Uploads;
use UploadThing\Resources\Webhooks;
class UploadThingServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Uploads::class, function () {
return new Uploads();
});
$this->app->singleton(Webhooks::class, function () {
return new Webhooks();
});
}
}<?php
namespace App\Http\Controllers;
use UploadThing\Resources\Uploads;
use Illuminate\Http\Request;
class FileController extends Controller
{
public function upload(Request $request, Uploads $uploads)
{
$file = $request->file('file');
$uploaded = $uploads->uploadFile(
$file->getPathname(),
$file->getClientOriginalName(),
$file->getMimeType()
);
return response()->json(['file' => $uploaded]);
}
}We welcome contributions! Please see our Contributing Guide for details.
If you discover a security vulnerability, please see our Security Policy.
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a list of changes and version history.