提交 90a99718 authored 作者: 吴德鹏's avatar 吴德鹏

图片上传

上级 565c33bb
......@@ -10,8 +10,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Auther: wudepeng
......@@ -30,17 +33,31 @@ public class UploadController {
@PostMapping("/uploadFile")
public Result uploadFile(@RequestBody String strImg) throws Exception {
Result<String> result = new Result<>();
String url = sendFile(strImg,api);
String url = sendFile(strImg, api);
result.setData(url).setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
private static String sendFile(String strImg,String api){
@PostMapping("/uploadFile1")
public Result uploadFile1(@RequestBody String[] strImg) throws Exception {
Result<List<String>> result = new Result<>();
List<String> urlList = new ArrayList<>();
for (int i = 0; i < strImg.length; i++) {
String url = sendFile(strImg[i], api);
System.out.println(url);
urlList.add(url);
}
result.setData(urlList).setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
private static String sendFile(String strImg, String api) {
try {
if (!StringUtils.isBlank(strImg)) {
Map<String,Object> map = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("file", strImg);
String url = HttpClientUtil.sendPostWithBodyParameter(api, map);
return url.substring(1, url.length() - 1);
......@@ -57,8 +74,8 @@ public class UploadController {
//@ApiOperation("删除文件")
@DeleteMapping("/delFile")
public Result delFile(@RequestParam("url") String url) {
Result<Map<String,Object>> result = new Result<>();
Map<String,Object> map = new HashMap<>();
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> map = new HashMap<>();
boolean b = OssUtil.deleteFile(url);
map.put("isDeleted", b);
result.setData(map).setMessage(ResultCodeEnum.SUCCESS.getDesc());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论