|
|
@@ -9,10 +9,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -37,6 +34,13 @@ public class SysFileController
|
|
|
@Value("${file.secretKey}")
|
|
|
public String secretKey;
|
|
|
|
|
|
+ @Value("${file.domain}")
|
|
|
+ public String networkAdd;
|
|
|
+
|
|
|
+ @Value("${file.prefix}")
|
|
|
+ public String prefix;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private static final String FILE_SUFFIX = "FILE_CODE_";
|
|
|
|
|
|
@@ -52,8 +56,9 @@ public class SysFileController
|
|
|
String url = sysFileService.uploadFile(file);
|
|
|
SysFile sysFile = new SysFile();
|
|
|
sysFile.setName(FileUtils.getName(url));
|
|
|
- sysFile.setUrl(url);
|
|
|
String code = DesUtil.encrypt(url, secretKey);
|
|
|
+ url = prefix + url;
|
|
|
+ sysFile.setUrl(url);
|
|
|
sysFile.setCode(code);
|
|
|
return R.ok(sysFile);
|
|
|
}
|
|
|
@@ -73,8 +78,9 @@ public class SysFileController
|
|
|
String url = sysFileService.uploadFile(file,busType);
|
|
|
SysFile sysFile = new SysFile();
|
|
|
sysFile.setName(FileUtils.getName(url));
|
|
|
- sysFile.setUrl(url);
|
|
|
String code = DesUtil.encrypt(url, secretKey);
|
|
|
+ url = prefix + url;
|
|
|
+ sysFile.setUrl(url);
|
|
|
sysFile.setCode(code);
|
|
|
return R.ok(sysFile);
|
|
|
}
|
|
|
@@ -96,7 +102,21 @@ public class SysFileController
|
|
|
log.error("下载文件失败", e);
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 路径参数
|
|
|
+ * @param response
|
|
|
+ * @param code
|
|
|
+ */
|
|
|
+ @GetMapping("/getFile/{code}")
|
|
|
+ public void getFile(HttpServletResponse response, @PathVariable String code){
|
|
|
+ try {
|
|
|
+ String filePath = DesUtil.decode(code, secretKey);
|
|
|
+ sysFileService.downloadFile(response,filePath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("下载文件失败", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|