You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
package {{ package.Controller }};
|
|
import {{ package.Common }}.unit.FilesUtil;
|
|
import {{ package.Common }}.unit.Md5HashUtil;
|
|
import {{ package.Common }}.unit.MinioUpComponent;
|
|
import {{ package.Common }}.vo.Result;
|
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* <p>
|
|
* 上传控制器
|
|
* </p>
|
|
*
|
|
* @author tiger
|
|
* @since 2024-06-04
|
|
*/
|
|
@Api(tags = "文件上传")
|
|
@RestController
|
|
@CrossOrigin(origins = "*")
|
|
@RequestMapping("/models/file")
|
|
public class MinioUpController {
|
|
|
|
@Autowired
|
|
private MinioUpComponent minioUpComponent;
|
|
|
|
@ApiOperation(value = "图片上传")
|
|
@CrossOrigin(origins = "*")
|
|
@PostMapping(value = "/upImg")
|
|
public Result<?> up(@RequestParam("file") MultipartFile file) {
|
|
if (file.isEmpty()) {
|
|
return Result.error("请选择一个文件上传");
|
|
}
|
|
// 文件上传路径 可以为空 默认 bucketName: "health-bucket" 桶的名字为根目录
|
|
// String path = "/tmp/user";
|
|
String path = "";
|
|
String url = "";
|
|
try {
|
|
url = minioUpComponent.uploadImg(path,Md5HashUtil.getMD5Hash(file.getBytes()) +
|
|
FilesUtil.getFileExtension(file), file.getInputStream());
|
|
} catch (IOException e) {
|
|
return Result.error("上传失败");
|
|
}
|
|
return Result.OK(url);
|
|
}
|
|
|
|
|
|
}
|
|
|