文件上传接口实现

This commit is contained in:
张松
2025-02-12 16:40:34 +08:00
parent 6725f7bf32
commit 2352814466
6 changed files with 102 additions and 6 deletions

View File

@@ -2,11 +2,16 @@ package com.czg.controller;
import com.czg.account.service.CommonService;
import com.czg.resp.CzgResult;
import com.czg.service.account.util.AliOssUtil;
import jakarta.annotation.Resource;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* 公共接口
@@ -17,6 +22,8 @@ import org.springframework.web.bind.annotation.RestController;
public class CommonController {
@Resource
private CommonService commonService;
@Resource
private AliOssUtil aliOssUtil;
/**
* 发送验证码
@@ -27,4 +34,14 @@ public class CommonController {
public CzgResult<Boolean> sendSms(@RequestParam String type) {
return CzgResult.success(commonService.sendSms(type));
}
/**
* 文件上传
* @param file 文件对象
* @return 文件地址
*/
@PostMapping("/upload")
public CzgResult<String> upload(@RequestParam MultipartFile file) throws Exception {
return CzgResult.success(aliOssUtil.uploadSuffix(file.getBytes(), FilenameUtils.getExtension(file.getOriginalFilename())));
}
}