From 21012be2d4a839aa512d84126a6a9bcaeb13efe2 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 23 Dec 2020 14:11:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/TestController.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/TestController.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/TestController.java index 1009352893..4df11b32fe 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/TestController.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/TestController.java @@ -1,21 +1,23 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.result.UploadImgResultDTO; +import com.epmet.service.OssService; import org.apache.commons.io.FileUtils; -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.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; @RestController @RequestMapping("test") public class TestController { + @Autowired + private OssService ossService; + @PostMapping("local-upload") public Result localUpload(@RequestPart("file") MultipartFile file) { @@ -28,4 +30,17 @@ public class TestController { } return new Result(); } + + @PostMapping("upload2aliyun") + public Result upload2aliyun() { + try (final FileInputStream fis = new FileInputStream("/opt/upload_files/temp")) { + final MockMultipartFile mockMultipartFile = new MockMultipartFile("temp", fis); + return ossService.uploadImg(mockMultipartFile); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return new Result(); + } }