编号:ZSSAC-585 描述:生成二维码与文件上传修改
This commit is contained in:
parent
e8ded5cae2
commit
178fdaf4c0
@ -132,6 +132,7 @@ xss:
|
|||||||
file:
|
file:
|
||||||
ceph:
|
ceph:
|
||||||
#endpoint: http://127.0.0.1:9000
|
#endpoint: http://127.0.0.1:9000
|
||||||
|
upload: http://192.168.1.23:9000
|
||||||
endpoint: http://file.sac.zsmarter.com
|
endpoint: http://file.sac.zsmarter.com
|
||||||
# 50M
|
# 50M
|
||||||
defaultMaxSize: 52428800
|
defaultMaxSize: 52428800
|
||||||
|
@ -15,7 +15,12 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring框架基本的核心工具 -->
|
<!-- 生成二维码 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.glxn.qrgen</groupId>
|
||||||
|
<artifactId>javase</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency> <!-- Spring框架基本的核心工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
@ -320,5 +320,32 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public static MultipartFile fileToMultipartFile(File file) throws IOException {
|
||||||
|
try {
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(fis.available());
|
||||||
|
byte[] bytes = new byte[fis.available()];
|
||||||
|
int temp;
|
||||||
|
while ((temp = fis.read(bytes)) != -1) {
|
||||||
|
baos.write(bytes, 0, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件输出流
|
||||||
|
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||||
|
FileItem item = factory.createItem("image", "image/png", false, "123.png");
|
||||||
|
OutputStream os = item.getOutputStream();
|
||||||
|
os.write(bytes);
|
||||||
|
fis.close();
|
||||||
|
baos.close();
|
||||||
|
os.flush();
|
||||||
|
|
||||||
|
// MultipartFile
|
||||||
|
MultipartFile multipartFile = new CommonsMultipartFile(item);
|
||||||
|
return multipartFile;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("二维码转换异常");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.sf.common.utils.file;
|
||||||
|
|
||||||
|
|
||||||
|
import net.glxn.qrgen.core.image.ImageType;
|
||||||
|
import net.glxn.qrgen.javase.QRCode;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class QRCodeUtils {
|
||||||
|
|
||||||
|
public static MultipartFile generateQRCode(String data) throws IOException {
|
||||||
|
File qrCodeFile = QRCode.from(data).to(ImageType.PNG).file();
|
||||||
|
return FileUtils.fileToMultipartFile(qrCodeFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AmazonConfig {
|
public class AmazonConfig {
|
||||||
@Value("${file.ceph.endpoint}")
|
@Value("${file.ceph.upload}")
|
||||||
private String FILE_CEPH_POINT;
|
private String FILE_CEPH_POINT;
|
||||||
|
|
||||||
@Value("${file.ceph.access.key}")
|
@Value("${file.ceph.access.key}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user