|
@@ -17,6 +17,7 @@ use app\store\model\UploadFile as UploadFileModel;
|
|
|
use app\common\enum\Setting as SettingEnum;
|
|
|
use app\common\enum\file\FileType as FileTypeEnum;
|
|
|
use app\common\library\storage\Driver as StorageDriver;
|
|
|
+use think\facade\Log;
|
|
|
use think\response\Json;
|
|
|
use Google\Cloud\Storage\StorageClient;
|
|
|
use Google\Auth\Credentials\ServiceAccountCredentials;
|
|
@@ -70,6 +71,21 @@ class Upload extends Controller
|
|
|
$model->add($fileInfo, FileTypeEnum::IMAGE, $groupId);
|
|
|
//$filePath = $fileInfo['file_path'];
|
|
|
//todo 上传到谷歌GCS
|
|
|
+ $keyFilePath = '/etc/nginx/nginx/html/dihua-01-5690813badec.json';
|
|
|
+ $storage = new StorageClient(['projectId' => 'dihua-01', 'keyFilePath' => $keyFilePath]);
|
|
|
+ $bucket = $storage->bucket('freeshippingvps');
|
|
|
+
|
|
|
+ $filePath = public_path($fileInfo['file_path']);
|
|
|
+ $storageObj = $bucket->upload(
|
|
|
+ fopen($filePath, 'r'),
|
|
|
+ [
|
|
|
+ 'name' => $fileInfo['file_path']
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ $name = $storageObj->name();
|
|
|
+ if (empty($name)){
|
|
|
+ Log::error('上传文件到google云失败');
|
|
|
+ }
|
|
|
|
|
|
// 图片上传成功
|
|
|
return $this->renderSuccess(['fileInfo' => $model->toArray()], '图片上传成功');
|