package com.sinata.web.controller.applet;
|
|
import com.sinata.common.core.domain.R;
|
import com.sinata.common.exception.ServiceException;
|
import com.sinata.system.service.OssService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestPart;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.IOException;
|
import java.util.Objects;
|
|
/**
|
* @author mitao
|
* @date 2024/12/23
|
*/
|
@Api(tags = {"文件上传接口"})
|
@RestController
|
@RequiredArgsConstructor
|
@RequestMapping("/applet/file")
|
public class AppFileController {
|
private final OssService ossService;
|
|
/**
|
* 上传文件
|
*
|
* @param file
|
* @return
|
*/
|
@ApiOperation(value = "上传文件")
|
@PostMapping("/upload")
|
public R<String> upload(@RequestPart("file") MultipartFile file) {
|
|
if (Objects.isNull(file)) {
|
throw new ServiceException("文件不能为空");
|
}
|
String fileUrl;
|
try {
|
fileUrl = ossService.uploadFile(file);
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
return R.ok(fileUrl);
|
}
|
}
|