onix-systems-php/hyperf-file-upload

An extension to maintain file upload and assignation

v1.2.1 2024-02-29 08:59 UTC

This package is auto-updated.

Last update: 2024-03-29 09:13:19 UTC


README

Includes the following classes:

  • Model:
    • File;
    • FileRelations trait.
  • Repository:
    • FileRepository.
  • Service:
    • AddExternalFileService;
    • AddFileService;
    • ClearUnusedDeletedFilesService;
    • DownloadFileService.

Install:

composer require onix-systems-php/hyperf-file-upload

Publish config and database migrations:

php bin/hyperf.php vendor:publish onix-systems-php/hyperf-file-upload

Fill file_upload config with file upload configuration, following existing examples.

Add $fileRelations config and FileRelations trait to models you want assign files to:

use FileRelations;

public $fileRelations = [
    'avatar' => [
        'limit' => 1,
        'required' => false,
        'mimeTypes' => [image/png', 'image/jpg', 'image/jpeg', 'image/bmp'],
        'presets' => [
            '150x150' => ['fit' => [150, 150]],
            '250x250' => ['fit' => [250, 250]],
        ],
    ],
    'documents' => [
        'limit' => null,
        'required' => false,
        'mimeTypes' => ['application/pdf'],
    ],
];

Methods you might need to redefine in FileRelations trait:

  • getAuth: this method should return active user
  • processFileActions: if you defined new extra actions in config, you'll need to define action's login in this method