|
...
|
...
|
@@ -48,24 +48,30 @@ class CosService |
|
|
|
// 如果不是 Base64 流文件,处理为普通文件上传
|
|
|
|
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
|
|
|
|
}
|
|
|
|
$options = [
|
|
|
|
'Bucket' => $cos['bucket'],
|
|
|
|
'Key' => $key,
|
|
|
|
'Body' => $Body,
|
|
|
|
];
|
|
|
|
//水印
|
|
|
|
if ($watermarkOptions) {
|
|
|
|
$options['PicOperations'] = json_encode([
|
|
|
|
'is_pic_info' => 1,
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'fileid' => $key, // 使用相同的文件名保存
|
|
|
|
'rule' => $watermarkOptions,
|
|
|
|
try {
|
|
|
|
$options = [
|
|
|
|
'Bucket' => $cos['bucket'],
|
|
|
|
'Key' => $key,
|
|
|
|
'Body' => $Body,
|
|
|
|
];
|
|
|
|
//水印
|
|
|
|
if ($watermarkOptions) {
|
|
|
|
$options['PicOperations'] = json_encode([
|
|
|
|
'is_pic_info' => 1,
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'fileid' => $key, // 使用相同的文件名保存
|
|
|
|
'rule' => $watermarkOptions,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
], true);
|
|
|
|
], true);
|
|
|
|
}
|
|
|
|
$res = $cosClient->putObject($options);
|
|
|
|
@file_put_contents(storage_path('logs/upload_images'), var_export($res, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}catch (\Exception $e){
|
|
|
|
@file_put_contents(storage_path('logs/upload_images'), var_export($e->getMessage(), true) . PHP_EOL, FILE_APPEND);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$res = $cosClient->putObject($options);
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|