PHP code example of filacare / flysystem-oss

1. Go to this page and download the library: Download filacare/flysystem-oss 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/ */

    

filacare / flysystem-oss example snippets


use League\Flysystem\Filesystem;
use Filacare\Flysystem\Oss\OssAdapter;

$config = [
    'accessKeyId'     => 'yourAccessKeyId',      //         => false,
    'securityToken'   => null,
    'bucket'          => 'bucketName',           // tionKey'   => ''  // Must be 32 characters or ''
];
$adapter = new OssAdapter($config);
$driver = new Filesystem($adapter);

// use dirver
$driver->writeStream(...);
// use adapter
$adapter->getUrl($path);   // get web visit url
$adapter->bucket($bucket); // switch bucket in same endpoint
$adapter->cdnUrl($cdnUrl); // If you use cdn, don't forget to switch the cdn
// use client
$adapter->getClient()->uploadStream(...);

'oss' => [
    'driver'          => 'oss',
    'accessKeyId'     => env('OSS_ACCESS_KEY', ''),  // _ENDPOINT', ''),    // KET', ''),      // n
    'options'         => [],  // Custom oss request header options
    'visibility'      => env('OSS_VISIBILITY', 'public'),
    'encryptionKey'   => '' // Must be 32 characters or ''
],

use Illuminate\Support\Facades\Storage;
Storage::disk('oss')->put($path, $contents, $options = []);

'visibility' => 'private' // Optional, default visibility acl

$driver->writeStream(string $path, $contents, ['visibility' => 'private']);
Storage::disk('oss')->put($path, $contents, 'private');

'options' => [
    'x-oss-object-acl' => 'private' // public or private
]

'visibility' => 'public',

'encryptionKey'   => '', // Must be 32 characters or ''
'chunkSize'       => '', // Default is 4096
bash
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="config"