1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00

修正内容图片上传问题

This commit is contained in:
koogua 2022-09-06 11:03:19 +08:00
parent fbcc721828
commit 93ec72faf6
2 changed files with 16 additions and 70 deletions

View File

@ -99,43 +99,16 @@ class UploadController extends Controller
$file = $service->uploadContentImage();
if (!$file) {
return $this->jsonError(['msg' => '上传文件失败']);
return $this->jsonError([
'message' => '上传图片失败',
'error' => 1,
]);
}
$data = [
'src' => $service->getImageUrl($file->path),
'title' => $file->name,
];
return $this->jsonSuccess(['data' => $data]);
}
/**
* @Post("/remote/img", name="admin.upload.remote_img")
*/
public function uploadRemoteImageAction()
{
$originalUrl = $this->request->getPost('url', ['trim', 'string']);
$service = new StorageService();
$file = $service->uploadRemoteImage($originalUrl);
$newUrl = $originalUrl;
if ($file) {
$newUrl = $service->getImageUrl($file->path);
}
/**
* 编辑器要求返回的数据结构
*/
$data = [
'url' => $newUrl,
'originalURL' => $originalUrl,
];
return $this->jsonSuccess(['data' => $data]);
return $this->jsonSuccess([
'url' => $service->getImageUrl($file->path),
'error' => 0,
]);
}
/**

View File

@ -56,43 +56,16 @@ class UploadController extends Controller
$file = $service->uploadContentImage();
if (!$file) {
return $this->jsonError(['msg' => '上传文件失败']);
return $this->jsonError([
'message' => '上传图片失败',
'error' => 1,
]);
}
$data = [
'src' => $service->getImageUrl($file->path),
'title' => $file->name,
];
return $this->jsonSuccess(['data' => $data]);
}
/**
* @Post("/remote/img", name="home.upload.remote_img")
*/
public function uploadRemoteImageAction()
{
$originalUrl = $this->request->getPost('url', ['trim', 'string']);
$service = new StorageService();
$file = $service->uploadRemoteImage($originalUrl);
$newUrl = $originalUrl;
if ($file) {
$newUrl = $service->getImageUrl($file->path);
}
/**
* 编辑器要求返回的数据结构
*/
$data = [
'url' => $newUrl,
'originalURL' => $originalUrl,
];
return $this->jsonSuccess(['data' => $data]);
return $this->jsonSuccess([
'url' => $service->getImageUrl($file->path),
'error' => 0,
]);
}
}