承接 stianscholtz/s3-direct-uploader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stianscholtz/s3-direct-uploader

最新稳定版本:0.0.7

Composer 安装命令:

composer require stianscholtz/s3-direct-uploader

包简介

A headless Laravel file uploader to upload files to s3 directly from the client.

README 文档

README

S3DirectUploader is a headless Laravel package designed to facilitate direct file uploads to Amazon S3 from the client/browser. Please note that users need to build their own File Input, although a complimentary component will be available in the near future. This package then handles the uploaded files, creates corresponding file records in your database, and offers various features such as automatic thumbnail generation, image resizing and scaling, MIME type restrictions, and more.

Features

  • Direct file uploads to Amazon S3 from the client/browser.
  • Creation of file records in the database.
  • Laravel auto-discovery support.
  • S3DirectUploader Facade.
  • Config file with sensible defaults.
  • Route macro for convenience.
  • Automatic thumbnail generation (can be disabled).
  • Image resizing and scaling options.
  • MIME type restrictions.
  • File size restriction.
  • Prefixing file names.
  • Configurable disk via config/filesystems.php.

Installation

You can install the S3DirectUploader package via Composer. Run the following command:

composer require stianscholtz/s3-direct-uploader

The package will automatically register its service provider and Facade.

Configuration

After installing the package, you can update the config/s3-direct-uploader.php configuration file with your s3 disk, file model, default thumbnail dimensions, and other settings.

php artisan vendor:publish --provider="Stianscholtz\S3DirectUploader\UploaderServiceProvider" --tag=config

Database Migration

S3DirectUploader provides a migration file to create the files table in your database. To publish this migration, run:

php artisan vendor:publish

When prompted to select the service provider, choose:

Stianscholtz\S3DirectUploader\UploaderServiceProvider

Then, run the migration:

php artisan migrate

Usage

Route Macro

You can use the upload route macro for convenience or as an alternative to Route::match(['get', 'post']).

Route::upload('/upload', [UploadController::class, 'upload'])->name('file.upload');

instead of

Route::match(['get', 'post'], '/upload', [UploadController::class, 'upload'])->name('file.upload');

Controller

use S3DirectUploader;
use App\Models\Banner; // Assuming your model name is Banner

public function upload(Banner $banner): Model|array|File
{
    return S3DirectUploader::directory('directory/sub-directory/another-sub-directory')
        ->mimeType('application/pdf')
        ->mimeTypes('image/jpg', 'image/jpeg', 'image/png', 'image/webp')
        ->imagesOnly()
        ->scale(1200)
        ->resize(1200, 400)
        ->thumbnail(500, 500)
        ->thumbnail(false) // Disable thumbnail generation, if default dimesions are specified in config
        ->maxSize(15)
        ->unique(false)
        ->prefix('my-prefix-')
        ->disk('s3-public')// Use another s3 disk configured in config/filesystems.php
        ->after(function (File $file) use ($banner) {
            $banner->update(['file_id', $file->id]);
        })
        ->handle();
}

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-04