PHP code example of minz / laravel-filesystem-obs

1. Go to this page and download the library: Download minz/laravel-filesystem-obs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

minz / laravel-filesystem-obs example snippets


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



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);