uxf/storage
最新稳定版本:3.75.10
Composer 安装命令:
composer require uxf/storage
包简介
README 文档
README
Install
$ composer req uxf/storage
Migration
$this->addSql("
INSERT INTO uxf_storage.object
(parent_id, file_id, document_id, name, path, variant, \"order\", deleted, created_at, updated_at, type, locked)
VALUES
(NULL, NULL, NULL, '', '/', 'basic', 0, FALSE, NOW(), NOW(), 'folder', TRUE)
");
Config
// config/routes/uxf.php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routes): void {
$routes->import('@UXFStorageBundle/config/routes.php');
};
// config/packages/uxf.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('uxf_storage', [
'filesystems' => [
'default' => '%env(STORAGE_DSN)%', // default local
],
]);
};
| Storage | DSN | composer |
|---|---|---|
| Local | local://default/%kernel.project_dir%/public/upload | |
| AWS S3 | aws://key:secret@domain.com/bucket | league/flysystem-async-aws-s3 |
| Azure | azure://accountName:accountKey@core.windows.net/container | league/flysystem-azure-blob-storage |
| S3 | s3://key:secret@domain.com/bucket | |
| S3 http | s3://key:secret@domain.com/bucket?schema=http |
Usage
FileCreator
use League\Flysystem\FilesystemOperator;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UXF\Core\SystemProvider\Uuid;
use UXF\Storage\Entity\File;
use UXF\Storage\Entity\Image;
use UXF\Storage\Utils\DestinationDirHelper;
use UXF\Storage\Utils\MimeTypeHelper;
class UploadedFileCreator implements FileCreator
{
public function __construct(private readonly FilesystemOperator $defaultFilesystem)
{
}
public function createFile(object $file, ?string $namespace): ?File
{
if (!$file instanceof UploadedFile) {
return null;
}
$uuid = Uuid::uuid4();
$type = $file->getClientMimeType();
$ext = $file->getClientOriginalExtension();
$ext = $ext !== '' ? $ext : (MimeTypeHelper::convertToExtension($type) ?? 'jpg');
$size = $file->getSize();
$raw = $file->getContent();
$destDir = DestinationDirHelper::getDir($uuid, $namespace);
$this->defaultFilesystem->write("$destDir/$uuid.$ext", $file->getContent());
$originalName = $file->getClientOriginalName();
if (MimeTypeHelper::isImage($type)) {
$result = getimagesizefromstring($raw);
assert($result !== false);
[$width, $height] = $result;
return new Image($uuid, $ext, $type, $originalName, $namespace, $size, $width ?? 0, $height ?? 0);
}
return new File($uuid, $ext, $type, $originalName, $namespace, $size);
}
}
统计信息
- 总下载量: 16.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-30