<?php

namespace Modules\Common\Support\Upload\HuaweiOBS;

use Obs\ObsClient;

class HuaweiOBSOperator
{
    public static function postFile($pathAndFileName, $fileContent) {
        require_once app_path('Libs/HuaweiObsSdk/obs-autoloader.php');
        $objectKey =  $pathAndFileName;
        $obsConfig = config('common.huaweiCloud.OBS');
        $ak = $obsConfig['ak'];
        $sk = $obsConfig['sk'];
        $bucketName = $obsConfig['bucketName'];
        $obsClient = ObsClient::factory([
            'key' => $ak,
            'secret' => $sk,
            'endpoint' => $obsConfig['endpoint'],
            'socket_timeout' => 30,
            'connect_timeout' => 10
        ]);

        $resp = $obsClient->putObject(['Bucket' => $bucketName, 'Key' => $objectKey, 'Body' => $fileContent]);

        return $resp->toArray();
    }
}
