backstage/uploadcare-field
Composer 安装命令:
composer require backstage/uploadcare-field
包简介
Uploadcare Field component for the Backstage CMS.
README 文档
README
Nice to meet you, we're Vormkracht10
Hi! We are a web development agency from Nijmegen in the Netherlands and we use Laravel for everything: advanced websites with a lot of bells and whitles and large web applications.
About this package
This package adds an Uploadcare field to the Backstage CMS. Uploadcare is a powerful file handling platform that provides file uploads, storage, transformations and delivery. With this package, you can easily integrate Uploadcare's functionality into your Backstage CMS forms.
The field supports:
- Single and multiple file uploads
- Image previews
- File size limits
- Allowed file types
- Direct CDN delivery
- Image transformations
- Secure file storage
Once installed, you can use the Uploadcare field in your Backstage forms just like any other field type, while leveraging Uploadcare's robust file handling capabilities.
Other custom fields
For a list of other custom fields, please see the Backstage CMS documentation.
Installation
You can install the package via composer:
composer require backstage/uploadcare-field
Then you need to add the Uploadcare public key to your services.php config file:
return [ 'uploadcare' => [ 'public_key' => env('UPLOADCARE_PUBLIC_KEY') ] ];
Then you need to add the Uploadcare field to your backstage/fields.php config file:
return [ // ... 'custom_fields' => [ Backstage\UploadcareField\Uploadcare::class, ], ];
Automatic Migration
This package includes an automatic migration that fixes double-encoded JSON data in Uploadcare fields. This migration runs automatically when the package is installed or updated.
What the migration does:
- Fixes double-encoded JSON: Removes unnecessary JSON encoding layers that were created in earlier versions
- Updates both tables: Processes both
content_field_valuesandsettingstables - Safe execution: Only runs if the relevant tables exist
- Logging: Logs all changes for transparency and debugging
The migration will run automatically when you:
- Install the package for the first time
- Update the package via Composer
- Run
composer updateorcomposer install
⚠️ Important: This migration is not reversible. Always make a database backup before updating the package.
Usage
After adding the Uploadcare field to your backstage/fields.php config file, the field will automatically be available in the Backstage CMS.
Field Configuration
The Uploadcare field supports several configuration options:
- Multiple: Allow multiple file uploads
- With metadata: Store full file metadata (recommended for cropping support)
- Images only: Restrict uploads to image files only
- Uploader style: Choose between Inline, Minimal, or Regular uploader styles
Image Cropping and Transformations
The Uploadcare field stores comprehensive metadata about uploaded images, including cropping information. This allows you to access both the original and cropped versions of images in your front-end.
Understanding the Data Structure
When an image is uploaded and cropped, the field stores data in this format:
{
"uuid": "12345678-1234-1234-1234-123456789abc",
"cdnUrl": "https://ucarecdn.com/12345678-1234-1234-1234-123456789abc/-/crop/912x442/815,0/-/preview/",
"cdnUrlModifiers": "-/crop/912x442/815,0/-/preview/",
"fileInfo": {
"uuid": "12345678-1234-1234-1234-123456789abc",
"cdnUrl": "https://ucarecdn.com/12345678-1234-1234-1234-123456789abc/",
"imageInfo": {
"width": 1783,
"height": 442,
"format": "JPEG"
}
}
}
Cropping Parameters Explained
The cropping is defined by URL parameters:
-/crop/912x442/815,0/:912x442= target width and height815,0= x,y coordinates where cropping starts
-/preview/= preview mode
Front-end Usage
1. Direct URL Access
// Access the cropped version $croppedUrl = $image['cdnUrl']; // Contains crop parameters // Access the original version $originalUrl = $image['fileInfo']['cdnUrl']; // No crop parameters
2. Using Uploadcare Transformations
If you have the backstage/php-uploadcare-transformations package installed:
// Basic resize $resizedImage = uc($image['uuid'])->resize(width: 800); // Smart crop with AI $smartCropped = uc($image['uuid'])->smartCrop(width: 400, height: 300, type: 'smart_objects'); // Manual crop $manualCrop = uc($image['uuid'])->crop(width: 400, height: 300, x: 100, y: 50);
3. In Blade Templates
{{-- Use the pre-cropped version --}} <img src="{{ $image['cdnUrl'] }}" alt="Cropped image" /> {{-- Use the original version --}} <img src="{{ $image['fileInfo']['cdnUrl'] }}" alt="Original image" /> {{-- Apply new transformations --}} <img src="{{ uc($image['uuid'])->resize(width: 600) }}" alt="Resized image" />
Best Practices
-
Enable metadata storage: Set
withMetadata: truein your field configuration to ensure cropping information is preserved. -
Use appropriate versions:
- Use
cdnUrlfor pre-cropped images - Use
fileInfo.cdnUrlfor original images - Apply new transformations as needed
- Use
-
Performance considerations:
- Pre-cropped images load faster than on-the-fly transformations
- Use appropriate image sizes for your use case
- Consider using WebP format for better compression
-
Responsive images: Use different crop sizes for different screen sizes:
// Mobile $mobileImage = uc($image['uuid'])->resize(width: 400); // Desktop $desktopImage = uc($image['uuid'])->resize(width: 1200);
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.
backstage/uploadcare-field 适用场景与选型建议
backstage/uploadcare-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 431 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「vormkracht10」 「backstage-uploadcare-field」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 backstage/uploadcare-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 backstage/uploadcare-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 backstage/uploadcare-field 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Is your Laravel app OK? Health checks running in production to ensure you can sleep well at night and be sure everything is still OK.
Laravel package to generate dynamic Open Graph images
This package provides Genesys OAuth 2.0 support for the PHP League's OAauth 2.0 Client
This package minifies HTML responses in Laravel safely.
Laravel Instagram Component
This is my package agents
统计信息
- 总下载量: 431
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-24