hernol/uploadthing-php
Composer 安装命令:
composer require hernol/uploadthing-php
包简介
A high-quality PHP client for the UploadThing v6 REST API
关键字:
README 文档
README
A simplified, Laravel-focused PHP client for the UploadThing v6 REST API.
Features
- ✅ 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
Quick Start
Installation
composer require hernol/uploadthing-php
Configuration
Set 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
Basic Usage
Upload a File
<?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"; }
Upload with Custom Name and MIME Type
<?php use UploadThing\Resources\Uploads; $uploads = new Uploads(); $file = $uploads->uploadFile( '/path/to/image.jpg', 'my-custom-name.jpg', 'image/jpeg' );
Handle Webhooks
<?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";
Handle Webhook from PHP Globals
<?php use UploadThing\Resources\Webhooks; $webhooks = new Webhooks(); $event = $webhooks->handleWebhookFromGlobals( env('UPLOADTHING_WEBHOOK_SECRET') );
V6 API Endpoint
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)
Error Handling
<?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(); }
Examples
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
Documentation
Requirements
- PHP 8.1 or higher
- Composer
- UploadThing API key
Supported PHP Versions
| PHP Version | Support |
|---|---|
| 8.1 | ✅ Full support |
| 8.2 | ✅ Full support |
| 8.3 | ✅ Full support |
Laravel Integration
Service Provider (Optional)
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(); }); } }
Usage in Controllers
<?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]); } }
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Security
If you discover a security vulnerability, please see our Security Policy.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
hernol/uploadthing-php 适用场景与选型建议
hernol/uploadthing-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 621 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「API-Client」 「webhooks」 「multipart」 「rest-api」 「file-upload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hernol/uploadthing-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hernol/uploadthing-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hernol/uploadthing-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Makes your AmoCRM Webhooks looks pretty
Skolkovo API Client
Handle Zoom.us webhooks in a Laravel application
Production-ready third-party integrations for Laravel. Credential management, API request logging, rate limiting, sync scheduling, OAuth2, and health monitoring.
A client library for the OpenPLZ API project
Alfabank REST API integration
统计信息
- 总下载量: 621
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-04