|
|
|
@ -1,8 +1,13 @@ |
|
|
|
package com.bnyer.file.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.bnyer.common.core.domain.R; |
|
|
|
import com.bnyer.file.service.IFileService; |
|
|
|
import com.bnyer.file.service.IQiniuService; |
|
|
|
import com.bnyer.file.service.ITikTokImage; |
|
|
|
import com.bnyer.file.service.MinioService; |
|
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
|
import com.bnyer.file.vo.TiktokImgVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
@ -12,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@ -22,30 +28,65 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@Slf4j |
|
|
|
public class SysFileController |
|
|
|
{ |
|
|
|
public class SysFileController { |
|
|
|
@Autowired |
|
|
|
private MinioService minioService; |
|
|
|
@Autowired |
|
|
|
private IQiniuService qiniuService; |
|
|
|
@Autowired |
|
|
|
private ITikTokImage tikTokImage; |
|
|
|
@Autowired |
|
|
|
private IFileService fileService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量上传图片 |
|
|
|
*/ |
|
|
|
@PostMapping("/uploadBatch") |
|
|
|
public R<List<String>> uploadBatch(MultipartFile[] files) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
public R<List<String>> uploadBatch(MultipartFile[] files) { |
|
|
|
try { |
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
for (MultipartFile file : files) { |
|
|
|
String url = qiniuService.userUpload(file); |
|
|
|
list.add(url); |
|
|
|
} |
|
|
|
// 上传并返回访问地址
|
|
|
|
return R.ok(list); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("上传文件失败", e); |
|
|
|
return R.fail("上传文件失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量上传压缩图片 |
|
|
|
* @param files |
|
|
|
* @return |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
@PostMapping("/uploadBatchCompImg") |
|
|
|
public R<List<String>> compression(MultipartFile[] files) throws IOException { |
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
for (MultipartFile file : files) { |
|
|
|
String url = minioService.uploadFile(file); |
|
|
|
MultipartFile file1 = ImgUtil.commpressPicCycle(100, 0.5f, file); |
|
|
|
System.out.println("sssss"); |
|
|
|
String url = qiniuService.userUpload(file1); |
|
|
|
list.add(url); |
|
|
|
} |
|
|
|
|
|
|
|
// 上传并返回访问地址
|
|
|
|
return R.ok(list); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量审核 |
|
|
|
*/ |
|
|
|
@PostMapping("/checkBatch") |
|
|
|
public R<List<TiktokImgVo>> checkBatch(ArrayList<MultipartFile> files) { |
|
|
|
try { |
|
|
|
ArrayList<TiktokImgVo> list = fileService.checkImg(files); |
|
|
|
// 上传并返回访问地址
|
|
|
|
return R.ok(list); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("上传文件失败", e); |
|
|
|
return R.fail("上传文件失败"); |
|
|
|
} |
|
|
|
@ -55,11 +96,17 @@ public class SysFileController |
|
|
|
@ResponseBody |
|
|
|
public R upload(@RequestParam("file") MultipartFile file) { |
|
|
|
String url = null; |
|
|
|
try{ |
|
|
|
try { |
|
|
|
//url = minioService.uploadFile(file);
|
|
|
|
url=qiniuService.userUpload(file); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("文件上传失败,原因为:【{}】",e.getMessage()); |
|
|
|
// url=qiniuService.userUpload(file);
|
|
|
|
String imageString = ImgUtil.getImageString(file); |
|
|
|
//System.out.println(imageString);
|
|
|
|
//JSONObject jsonObject = qiniuService.checkImageContent("data:application/octet-stream;base64," + imageString);
|
|
|
|
System.out.println("================================="); |
|
|
|
//System.out.println(jsonObject);
|
|
|
|
tikTokImage.checkImageContent(file); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("文件上传失败,原因为:【{}】", e.getMessage()); |
|
|
|
return R.fail("文件上传失败!"); |
|
|
|
} |
|
|
|
return R.ok(url); |
|
|
|
@ -68,7 +115,7 @@ public class SysFileController |
|
|
|
@PostMapping("/download") |
|
|
|
@ResponseBody |
|
|
|
public R download(@RequestParam("fileName") String fileName, HttpServletResponse response) { |
|
|
|
minioService.download(fileName,response); |
|
|
|
minioService.download(fileName, response); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -76,10 +123,10 @@ public class SysFileController |
|
|
|
@ResponseBody |
|
|
|
public R uploadBanner(@RequestParam("file") MultipartFile file) { |
|
|
|
String url = null; |
|
|
|
try{ |
|
|
|
try { |
|
|
|
url = minioService.uploadBanner(file); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("文件上传失败,原因为:【{}】",e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("文件上传失败,原因为:【{}】", e.getMessage()); |
|
|
|
return R.fail("banner上传失败!"); |
|
|
|
} |
|
|
|
return R.ok(url); |
|
|
|
|