fix(biji): 修复图片上传和预览相关问题
-优化图片预览接口返回信息,提高错误处理的可读性- 在图片上传时添加基础 URL,确保正确的图片路径 - 更新 Vite 配置,修复开发环境的代理设置
This commit is contained in:
@@ -64,12 +64,14 @@ public class ImageController {
|
|||||||
public void preview(@PathVariable String url, HttpServletResponse resp) throws IOException {
|
public void preview(@PathVariable String url, HttpServletResponse resp) throws IOException {
|
||||||
if (StrUtil.isBlank(url)) {
|
if (StrUtil.isBlank(url)) {
|
||||||
resp.setStatus(404);
|
resp.setStatus(404);
|
||||||
R.fail("文件不存在");
|
resp.getWriter().write("{\"code\":404,\"msg\":\"文件不存在\",\"data\":null}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(rootPath + File.separator + url);
|
File file = new File(rootPath + File.separator + url);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
resp.setStatus(404);
|
resp.setStatus(404);
|
||||||
R.fail("文件不存在");
|
resp.getWriter().write("{\"code\":404,\"msg\":\"文件不存在\",\"data\":null}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
String contentTypeFromFileExtension = getContentTypeFromFileExtension(url);
|
String contentTypeFromFileExtension = getContentTypeFromFileExtension(url);
|
||||||
// 设置正确的 MIME
|
// 设置正确的 MIME
|
||||||
|
|||||||
@@ -66,9 +66,10 @@ const initVditor = () => {
|
|||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
uploadImage(file).then(res => {
|
uploadImage(file).then(res => {
|
||||||
const url = res.url;
|
const url = res.url;
|
||||||
// 使用 file.name 替代 files.name 保证一致性
|
// 使用 file.name 替代 files.name 保证一致性
|
||||||
vditor.value.insertValue(``);
|
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
|
||||||
|
vditor.value.insertValue(``);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
ElMessage.error('图片上传失败');
|
ElMessage.error('图片上传失败');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import path from 'path'
|
|||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const env = loadEnv(mode, process.cwd(), '')
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
return {
|
return {
|
||||||
// base: env.VITE_BASE_URL,
|
base: env.VITE_BASE_URL,
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
base: './',
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src')
|
'@': path.resolve(__dirname, './src')
|
||||||
@@ -17,7 +16,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:8084',
|
target: 'http://127.0.0.1:8084',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: path => path.replace(/^\/api/, '')
|
rewrite: path => path.replace(/^\/api/, '')
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
mydatabase.db
BIN
mydatabase.db
Binary file not shown.
Reference in New Issue
Block a user