Skip to content

minz/laravel-filesystem-obs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel filesystem obs

Obs storage for Laravel based on minz/huaweicloud-sdk-php-obs.

扩展包要求

  • PHP >= 7.0

安装命令

$ composer require "minz/laravel-filesystem-obs" -vvv

配置

1 将服务提供者 Minz\Obs\ObsServiceProvider::class 注册到 config/app.php 文件:

'providers' => [
    // Other service providers...
    Minz\Obs\ObsServiceProvider::class,
],

Laravel 5.5+ 会自动注册服务提供者可过滤

2 在 config/filesystems.php 配置文件中添加你的新驱动

<?php

return [
   'disks' => [
        //...
        'obs' => [
                    'driver' => 'obs',
                    'accessKey' => env('OBS_ACCESS_ID'),
                    'secretKey' => env('OBS_ACCESS_KEY'),
                    'bucket' => env('OBS_DEFAULT_BUCKET'),
                    'endpoint' => env('OBS_DEFAULT_ENDPOINT'), //自定义外部域名比如cdn或者bucket默认endpoint
                    'isCName' => env('OBS_DEFAULT_CNAME', false), //isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url如果cdnDomain未设置则使用endpoint来生成url否则使用cdn
                    'sslVerify' => env('OBS_DEFAULT_SSL_VERIFY', true), // use https
                    'buckets' => [
                        'video' => [
                            'bucket' => env('OBS_VIDEO_BUCKET'),
                            'endpoint' => env('OBS_VIDEO_ENDPOINT'),
                            'isCName' => env('OBS_VIDEO_CNAME', false), 
                            'sslVerify' => env('OBS_VIDEO_SSL_VERIFY', true),
                        ]
                    ]
                ],
        //...
    ]
];

基本使用

    $obs = Storage::disk('obs');
    //上传到默认bucket
    $defaultUploadTokenArray = $obs->uploadToken('objectname.txt');
    //切换到其他bucket
    $otherUploadTokenArray = $obs->bucket('video')->uploadToken('objectname2.txt');
    
    /**
     * 获取签名URL
     *
     * @param string $key
     * @param int $expires
     * @param string $method
     * @return string
     */
    $url = $obs->createSignedUrl($key, $expires = 3600, $method = "GET");
    
    /**
     * 写入文件
     * 
     * @param string $path
     * @param string $contents
     * @param Config $config
     * @return array|bool|false
     */    
    $writeStatus = $obs->write($key, $path);

依赖的核心包

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages