PHP code example of catlabinteractive / central-storage-client
1. Go to this page and download the library: Download catlabinteractive/central-storage-client 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');
catlabinteractive / central-storage-client example snippets
$centralStorageClient = new CentralStorageClient(
'https://your-central-storage-url.com',
'your_key',
'your_secret',
'cdn_frontend_url'
);
'providers' => [
[...]
CatLab\CentralStorage\Client\CentralStorageServiceProvider::class,
],
'aliases' => [
[...]
'CentralStorage' => CatLab\CentralStorage\Client\CentralStorageClientFacade::class,
]
]
use App\Models\Attachments\Asset;
use Illuminate\Http\Request;
class AssetController
{
public function upload(Request $request)
{
$file = $request->file()->first();
if (!$file) {
abort(400, 'Please provide a valid file.');
}
if (!$file->isValid()) {
abort(400, 'File not valid: ' . $file->getErrorMessage());
}
$asset = \CentralStorage::store($file);
$asset->save();
return response()->json($asset->getData());
}
}