|
@@ -0,0 +1,42 @@
|
|
|
|
+package com.cicv.oss.config.adapter.controller;
|
|
|
|
+
|
|
|
|
+import com.cicv.oss.config.adapter.entity.OssConfigInfo;
|
|
|
|
+import com.cicv.oss.config.infra.config.OssConfig;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
|
+import org.springframework.core.io.ResourceLoader;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/ros")
|
|
|
|
+public class RosController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResourceLoader resourceLoader;
|
|
|
|
+
|
|
|
|
+ @GetMapping("/config")
|
|
|
|
+ public void download(HttpServletResponse response, @RequestParam("fileName") String fileName) {
|
|
|
|
+ try {
|
|
|
|
+ response.setContentType("application/octet-stream;charset=utf-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:your-file.txt");
|
|
|
|
+ InputStream inputStream = resource.getInputStream();
|
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
+ for (int bytesRead = inputStream.read(buffer); bytesRead >= 0; bytesRead = inputStream.read(buffer)) {
|
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|