增加远程url和base64转pdf接口

master
chenjf 2 years ago
parent 370ea2592f
commit 13969628f8

@ -79,4 +79,22 @@ public class FileDetailController {
ilsFileDetailService.downloadByUrl(url, response);
}
/**
* url
*/
@ApiOperation("根据url和文件后缀上传文件")
@RequestMapping(value = "uploadByUrl", method = RequestMethod.POST)
public FileInfo uploadByUrl(String url, String contentType, HttpServletResponse response) throws IOException {
return ilsFileDetailService.uploadByUrl(url, contentType, response);
}
/**
* base64
*/
@ApiOperation("根据url和文件后缀上传文件")
@RequestMapping(value = "uploadByBase64", method = RequestMethod.POST)
public FileInfo uploadByBase64(String base64, String contentType, HttpServletResponse response) throws IOException {
return ilsFileDetailService.uploadByBase64(base64, contentType, response);
}
}

@ -4,6 +4,7 @@ import cn.xuyanwu.spring.file.storage.FileInfo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
@ -37,4 +38,21 @@ public interface IlsFileDetailService {
* @param url
*/
public void downloadByUrl(String url, HttpServletResponse response) throws IOException;
/**
* url
* @param url
* @param contentType
*/
public FileInfo uploadByUrl(String url, String contentType, HttpServletResponse response) throws FileNotFoundException;
/**
* base64
* @param base64
* @param contentType
*/
public FileInfo uploadByBase64(String base64, String contentType, HttpServletResponse response) throws FileNotFoundException;
}

@ -1,5 +1,6 @@
package org.ils.file.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.xuyanwu.spring.file.storage.Downloader;
import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
@ -11,10 +12,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.util.Base64;
/**
@ -25,6 +24,8 @@ import java.io.OutputStream;
@Slf4j
@Service
public class IlsFileDetailServiceImpl implements IlsFileDetailService {
private static final String SPLIT_STR = ".";
@Autowired
private FileStorageService fileStorageService;
@ -86,4 +87,16 @@ public class IlsFileDetailServiceImpl implements IlsFileDetailService {
toClient.close();
}
@Override
public FileInfo uploadByUrl(String url, String contentType, HttpServletResponse response) throws FileNotFoundException {
FileInfo fileInfo = fileStorageService.of(url).setOriginalFilename(System.currentTimeMillis() + SPLIT_STR + contentType).upload();
return fileInfo;
}
@Override
public FileInfo uploadByBase64(String base64, String contentType, HttpServletResponse response) throws FileNotFoundException {
FileInfo fileInfo = fileStorageService.of(Base64.getDecoder().decode(base64)).setOriginalFilename(System.currentTimeMillis() + SPLIT_STR + contentType).upload();
return fileInfo;
}
}

Loading…
Cancel
Save