前台部分接口
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\ProjectModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Service\common\upload\QiniuStorageService;
|
||||
use App\Service\FileService;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
@@ -20,28 +21,52 @@ class UploadService extends BaseService
|
||||
$this->model = RoleModel::class;
|
||||
}
|
||||
|
||||
public function uploadImage($file)
|
||||
/**
|
||||
* 上传OSS图片
|
||||
* @param $file
|
||||
* @return array|bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadImage($file): array|bool
|
||||
{
|
||||
// 获取文件后缀
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$key = 'spa/image/'. date('Ymd') . '/' . 'cc_upload_'. Str::random(). uniqid() . '.' . $ext;
|
||||
return [
|
||||
// $result = QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
$result = [
|
||||
'key' => $key,
|
||||
'url' => 'https://img2.baidu.com/it/u=1629222614,1358629025&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500&a='. rand(1111111, 9999999)
|
||||
];
|
||||
return QiniuStorageService::getInstance()->uploadImage($file, $key);
|
||||
FileService::getInstance()->create([
|
||||
'user_id' => $this->userId,
|
||||
'url' => $result['url'],
|
||||
]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function uploadVideo($file)
|
||||
/**
|
||||
* 上传OSS视频
|
||||
* @param $file
|
||||
* @return array|bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadVideo($file): array|bool
|
||||
{
|
||||
// 获取文件后缀
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$key = 'spa/video/'. date('Ymd') . '/' . 'cc_upload_'. Str::random(). uniqid() . '.' . $ext;
|
||||
return [
|
||||
// $result = QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
$result = [
|
||||
'key' => $key,
|
||||
'url' => 'http://d-jy.nailaoyun.cn/storage/video//20250410/ca1bbbb3af5853c7fc4ef23b8a918922.mp4?a='. rand(1111111, 9999999)
|
||||
'url' => 'https://img2.baidu.com/it/u=1629222614,1358629025&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500&a='. rand(1111111, 9999999)
|
||||
];
|
||||
return QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
FileService::getInstance()->create([
|
||||
'user_id' => $this->userId,
|
||||
'url' => $result['url'],
|
||||
]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user