eposgit/yii2-hejiang-storage

There is no license information available for the latest version (v1.0) of this package.

A file uploading extension for Yii2, saving files to object storage service.

v1.0 2021-01-25 06:12 UTC

This package is not auto-updated.

Last update: 2023-01-24 14:38:47 UTC


README

Thanks for your attention. This package is only used for my company projects, please do NOT use it in your product environment.

Usage

  1. Firstly, add this lines of code to your Yii application config:

    'components' => [
        'class' => 'Hejiang\Storage\Components\StorageComponent',
        'basePath' => 'temp/',
        'driver' => [
            'class' => 'Hejiang\Storage\Drivers\Local',
            'accessKey' => '',
            'secretKey' => '',
            'bucket' => '',
        ]
    ]
  2. Then after app bootstarpping, you would get the storage component instance like that:

    $storage = \Yii::$app->storage;

    Alternatively, you can also create a driver while app running:

    $storage->setDriver('Hejiang\Storage\Drivers\Local', []);
  3. Fetch uploaded file by field name:

    $file = $storage->getUploadedFile('FILE-FIELD-NAME');
  4. Save it.

    $url = $file->saveAs('NEW-FILE-NAME.EXT');
    // or
    $url = $file->saveWithOriginalExtension('NEW-FILE-BASE-NAME');
    // or
    $url = $file->saveAsUniqueHash();

    $url will be a URL string which can access this file on success, or false on failure.

    If there's any error occurred, these methods will throw a Hejiang\Storage\Exceptions\StorageException. Don't forget to try... catch ....

About

Working at: Zhejiang Hejiang Technology Co., Ltd.