铁路/远程存储

该包的最新版本(v3.0.0)没有可用的许可信息。

远程存储服务

v3.0.0 2024-08-19 20:31 UTC

This package is auto-updated.

Last update: 2024-09-19 20:40:19 UTC


README

通过我们的Laravel应用程序简化了对league/flysystem和AWS S3的使用的包装器。

安装、配置、使用

安装

运行 $ composer vendor:publish 将包的配置文件 "/config/remotestorage.php" 复制到您的应用程序的 "/config" 目录。

(假设您正在使用Composer、Laravel和AWS S3)

配置

定义以下环境变量并使用适当的值

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION
  • AWS_BUCKET

将服务提供者 (\Railroad\RemoteStorage\Providers\RemoteStorageServiceProvider) 添加到您应用程序的 /config/app.php 文件中的 'providers' 数组中

'providers' => [
    # ...
    \Railroad\RemoteStorage\Providers\RemoteStorageServiceProvider::class,
]

运行 $ php artisan vendor:publish 以复制配置文件并在您应用程序的 /config 目录中创建一个 remotestorage.php 文件。这将使用您在 .env 文件中提供的值并传递它们所需的。

使用

在需要的地方注入 Railroad\RemoteStorage\Services\RemoteStorageService

/** @var Railroad\RemoteStorage\Services\RemoteStorageService $remoteStorageService */
protected $remoteStorageService;

public function __constructor(Railroad\RemoteStorage\Services\RemoteStorageService $remoteStorageService){
    $this->remoteStorageService = $remoteStorageService;
}

在文件顶部包含命名空间

use Railroad\RemoteStorage\Services;

... 以避免在各个地方指定命名空间

/** @var RemoteStorageService $remoteStorageService */
protected $remoteStorageService;

public function __constructor(RemoteStorageService $remoteStorageService){
    $this->remoteStorageService = $remoteStorageService;
}

响应

read

用法示例(s)

$file = $this->remoteStorageService->read($filenameRelative);

参数

响应

exists

用法示例(s)

$exists = $this->remoteStorageService->exists('foo/bar.jpg');
/** 
 * @param Request $request
 * @return JsonResponse
 */
public function uploadThumbnailIfDoesNotAlreadyExist(Request $request)
{
    $target = 'foo/' . $request->get('target');    
    if(!$this->remoteStorageService->exists('foo/')){
        $upload = $this->remoteStorageService->put($target, $request->file('file'));
        throw_if((!$upload), new JsonResponse('Upload product thumbnail failed', 400));
    }
    return new JsonResponse(['exists' => true]);
}

参数

响应

delete

用法示例(s)

$this->remoteStorageService->delete('foo/bar.jpg');
public function deleteThumbnail(Request $request)
{
    $target = $request->get('target');    
    $delete = $this->remoteStorageService->delete('foo/' . $target);
    throw_if((!$delete), new JsonResponse('product thumbnail deletion failed', 400));
    return new JsonResponse(['deleted' => true]);
}

参数

响应

create_dir

[待办事项]

rename

[待办事项]

copy

[待办事项]

get_mimetype

[待办事项]

get_timestamp

[待办事项]

get_size

[待办事项]

delete_dir

[待办事项]