app首页视频封面,上传监控视频封面
This commit is contained in:
parent
3eb365c461
commit
b04c038bd3
|
@ -15,6 +15,7 @@
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
use app\common\enum\FileEnum;
|
use app\common\enum\FileEnum;
|
||||||
|
use app\common\model\file\File;
|
||||||
use app\common\service\UploadService;
|
use app\common\service\UploadService;
|
||||||
use Exception;
|
use Exception;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
@ -26,7 +27,7 @@ use think\response\Json;
|
||||||
*/
|
*/
|
||||||
class UploadController extends BaseApiController
|
class UploadController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
public array $notNeedLogin=['uploadVideoCover'];
|
||||||
/**
|
/**
|
||||||
* @notes 上传图片
|
* @notes 上传图片
|
||||||
* @return Json
|
* @return Json
|
||||||
|
@ -48,8 +49,36 @@ class UploadController extends BaseApiController
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$deviceId = $this->request->param('device_id', '');
|
$deviceId = $this->request->param('device_id', '');
|
||||||
$result = UploadService::image($deviceId, $this->userId,FileEnum::SOURCE_USER);
|
// Base64编码的图片字符串
|
||||||
return $this->success('上传成功', ['url'=>env('project.project_url').'/'.$result['url']]);
|
$base64Image = $this->request->param('image'); // 这里只展示部分内容
|
||||||
|
|
||||||
|
// 去除前面的"data:"标识
|
||||||
|
$base64Data = substr($base64Image, strpos($base64Image, ',') + 1);
|
||||||
|
|
||||||
|
// 将Base64编码的图片字符串转换为二进制数据
|
||||||
|
$binaryData = base64_decode($base64Data);
|
||||||
|
|
||||||
|
// 创建图像对象
|
||||||
|
$imageObject = imagecreatefromstring($binaryData);
|
||||||
|
$saveDir = 'uploads/images/' . date('Ymd'). '/';
|
||||||
|
if (!is_dir($saveDir)) {
|
||||||
|
mkdir($saveDir, 0755, true);
|
||||||
|
}
|
||||||
|
$fileName = uniqid().'.png';
|
||||||
|
|
||||||
|
// 保存图片
|
||||||
|
imagepng($imageObject, $saveDir.$fileName);
|
||||||
|
|
||||||
|
$file = File::create([
|
||||||
|
'cid' => $deviceId,
|
||||||
|
'type' => FileEnum::IMAGE_TYPE,
|
||||||
|
'name' => $fileName,
|
||||||
|
'uri' => $saveDir . $fileName,
|
||||||
|
'source' => FileEnum::SOURCE_USER,
|
||||||
|
'source_id' => $this->userId,
|
||||||
|
'create_time' => time(),
|
||||||
|
]);
|
||||||
|
return $this->success('上传成功', ['url'=>env('project.project_url').'/'.$saveDir.$fileName]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->fail($e->getMessage());
|
return $this->fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue