|
@@ -1,21 +1,17 @@
|
|
package com.qmth.exam.reserve.service.impl;
|
|
package com.qmth.exam.reserve.service.impl;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.nio.file.Files;
|
|
|
|
-import java.time.Duration;
|
|
|
|
-
|
|
|
|
|
|
+import com.qmth.boot.core.fss.store.FileStore;
|
|
|
|
+import com.qmth.boot.tools.models.ByteArray;
|
|
|
|
+import com.qmth.exam.reserve.service.FileUploadService;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.qmth.boot.core.fss.store.impl.OssStore;
|
|
|
|
-import com.qmth.boot.tools.models.ByteArray;
|
|
|
|
-import com.qmth.exam.reserve.config.SysProperty;
|
|
|
|
-import com.qmth.exam.reserve.service.FileUploadService;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class FileUploadServiceImpl implements FileUploadService {
|
|
public class FileUploadServiceImpl implements FileUploadService {
|
|
@@ -23,40 +19,21 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|
private final static Logger log = LoggerFactory.getLogger(FileUploadServiceImpl.class);
|
|
private final static Logger log = LoggerFactory.getLogger(FileUploadServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private SysProperty sysProperty;
|
|
|
|
|
|
+ private FileStore fileStore;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void uploadFile(String dirName, File file) {
|
|
public void uploadFile(String dirName, File file) {
|
|
try {
|
|
try {
|
|
- OssStore store = new OssStore(sysProperty.getServer(), sysProperty.getConfig());
|
|
|
|
- store.write(dirName, Files.newInputStream(file.toPath()), ByteArray.md5(file).toHexString());
|
|
|
|
- store.close();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.warn("文件上传出错", e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public String uploadByText(String dirName, String text, String fileName) {
|
|
|
|
- try {
|
|
|
|
- OssStore store = new OssStore(sysProperty.getServer(), sysProperty.getConfig());
|
|
|
|
- String filePath = dirName + "/" + fileName;
|
|
|
|
- ByteArray data = ByteArray.fromString(text);
|
|
|
|
- store.write(filePath, new ByteArrayInputStream(data.value()), ByteArray.md5(data.value()).toHexString());
|
|
|
|
- String url = store.getPresignedUrl(filePath, Duration.ofMinutes(5));
|
|
|
|
- store.close();
|
|
|
|
- return url;
|
|
|
|
|
|
+ fileStore.write(dirName, Files.newInputStream(file.toPath()), ByteArray.md5(file).toHexString());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.warn("文件上传出错", e);
|
|
log.warn("文件上传出错", e);
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public File downloadFile(String path, File localFile) {
|
|
public File downloadFile(String path, File localFile) {
|
|
try {
|
|
try {
|
|
- OssStore store = new OssStore(sysProperty.getServer(), sysProperty.getConfig());
|
|
|
|
- InputStream inputStream = store.read(path);
|
|
|
|
|
|
+ InputStream inputStream = fileStore.read(path);
|
|
FileUtils.copyInputStreamToFile(inputStream, localFile);
|
|
FileUtils.copyInputStreamToFile(inputStream, localFile);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.warn("下载文件出错", e);
|
|
log.warn("下载文件出错", e);
|