alareqi/smart-upload
Composer 安装命令:
composer require alareqi/smart-upload
包简介
Laravel package for mobile file uploads with Livewire-style temporary storage.
README 文档
README
Laravel package for mobile file uploads with temporary storage - no database required.
This package provides a simple way to handle file uploads from mobile apps. Files are uploaded to a temporary location, then moved to their final destination when the form is submitted.
Installation
composer require alareqi/smart-upload
No migrations needed - this package uses file-based temporary storage.
How It Works
┌─────────────┐ /upload-file ┌─────────────┐
│ Mobile App │ ────────────▶ │ Laravel │
│ │ │ Server │
│ 1.Select │ ◀─────────── │ 2.Return │
│ file │ upload │ signed │
│ │ URL │ URL │
│ 3.Upload │ ────────────▶ │ │
│ to URL │ 4.Upload │ │
│ │ file │ │
│5.Submit │ ────────────▶ │6.Move to │
│ form │ form │ final │
│ │ data │ location │
└─────────────┘ └─────────────┘
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/upload-file |
Upload file |
Upload File
Upload a file directly to the endpoint:
POST /api/upload-file Content-Type: multipart/form-data ------WebKitFormBoundary Content-Disposition: form-data; name="file"; filename="photo.jpg" Content-Type: image/jpeg [file content] ------WebKitFormBoundary--
Response:
{
"uuid": "abc-123-uuid",
"path": "tmp/abc-123.jpg",
"original_name": "photo.jpg",
"size": 1024,
"mime_type": "image/jpeg",
"temp_url": "https://yourapp.com/storage/tmp/abc-123.jpg",
"expires_at": "2024-01-01T12:00:00Z"
}
Laravel Controller Usage
Use the HasFileUploads trait in your controller:
use Alareqi\SmartUpload\Concerns\HasFileUploads; use Illuminate\Http\Request; class PostController extends Controller { use HasFileUploads; public function store(Request $request) { // Convert temporary upload to permanent storage $path = $this->convertUpload( $request->image_uuid, // UUID from mobile 'posts/images' // Final directory ); // Save to database Post::create([ 'title' => $request->title, 'image' => $path, ]); } }
Multiple Files
For multiple file uploads, pass an array of UUIDs:
use Alareqi\SmartUpload\Concerns\HasFileUploads; use Illuminate\Http\Request; class PostController extends Controller { use HasFileUploads; public function store(Request $request) { $imagePaths = []; // $request->image_uploads is array: ['uuid1', 'uuid2', 'uuid3'] foreach ($request->image_uploads as $uuid) { $imagePaths[] = $this->convertUpload( $uuid, 'posts/images' ); } // Save to database Post::create([ 'title' => $request->title, 'images' => json_encode($imagePaths), ]); } }
Or convert each with custom filename:
foreach ($request->images as $index => $uuid) { $path = $this->convertUpload( $uuid, 'posts/images', 'post_' . $post->id . '_image_' . $index . '.jpg' // Custom filename ); }
Configuration
Edit config/smart-upload.php:
return [ // Final storage disk 'disk' => env('SMART_UPLOAD_DISK', 'local'), // Temporary directory 'temp_directory' => env('SMART_UPLOAD_TEMP_DIR', 'smart-upload-tmp'), // Hours until temp file expires (also used as cache TTL) 'expiration_hours' => 24, // Max file size in KB 'max_file_size' => 10240, // Allowed mimes 'allowed_mimes' => ['jpg', 'jpeg', 'png', 'gif', 'pdf'], // Cache driver for metadata 'cache' => [ 'driver' => env('SMART_UPLOAD_CACHE_DRIVER', 'file'), ], // Temporary upload settings 'temporary_file_upload' => [ 'disk' => 'local', 'directory' => 'tmp', ], ];
Cleanup Command
Run cleanup to delete expired temporary files:
php artisan smart-upload:cleanup
Schedule it in app/Console/Kernel.php:
protected function schedule(Schedule $schedule) { $schedule->command('smart-upload:cleanup')->hourly(); }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
alareqi/smart-upload 适用场景与选型建议
alareqi/smart-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「alareqi」 「smart-upload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alareqi/smart-upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alareqi/smart-upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alareqi/smart-upload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Filament Captcha Field
Alfabank REST API integration
This is my package laravel-uploadable
This is my package laravel-blurhashable
This package add extended functionality to Wasender
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-20