feat(image): 优化图片上传和预览功能
- 修改图片上传接口,支持用户 ID 和 Markdown ID 参数 - 实现在线预览功能,支持多种文件类型 - 优化图片插入到 Markdown 编辑器的逻辑 - 更新数据库配置和连接字符串
This commit is contained in:
@@ -14,7 +14,7 @@ public interface ImageService extends IService<Image> {
|
||||
* @return 上传的图片对象
|
||||
* @throws IOException 文件操作异常
|
||||
*/
|
||||
Image uploadImage(MultipartFile file) throws IOException;
|
||||
Image uploadImage(MultipartFile file, Long userId, Long markdownId) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ImageServiceImpl
|
||||
private ImageMapper imageMapper;
|
||||
|
||||
@Override
|
||||
public Image uploadImage( MultipartFile file) throws IOException {
|
||||
public Image uploadImage( MultipartFile file, Long userId, Long markdownId) throws IOException {
|
||||
// 创建上传目录
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
@@ -53,10 +53,11 @@ public class ImageServiceImpl
|
||||
Image image = new Image();
|
||||
image.setOriginalName(originalFilename);
|
||||
image.setStoredName(storedName);
|
||||
image.setUrl("/uploads/" + storedName);
|
||||
image.setUrl("/api/images/preview/" + storedName);
|
||||
image.setSize(file.getSize());
|
||||
image.setContentType(file.getContentType());
|
||||
image.setCreatedAt(new Date());
|
||||
image.setMarkdownId(markdownId);
|
||||
|
||||
this.save(image);
|
||||
return image;
|
||||
|
||||
Reference in New Issue
Block a user