Update FileService.java
- Refactored code - Added simple getFileById()
This commit is contained in:
parent
05720583ba
commit
f3939d9f13
@ -35,7 +35,25 @@ public class FileService {
|
|||||||
this.fileUploadRepository = fileUploadRepository;
|
this.fileUploadRepository = fileUploadRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processUploadedFile(MultipartFile file, String uploaderIp) {
|
@PostConstruct
|
||||||
|
public void createFolder() {
|
||||||
|
Path path = Paths.get(getTempDirPath());
|
||||||
|
log.debug("Checking temp file directory " + path.getFileName());
|
||||||
|
try {
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
Files.createDirectory(path);
|
||||||
|
log.debug("Directory created");
|
||||||
|
} else {
|
||||||
|
log.debug("Directory already exists. Clearing content.");
|
||||||
|
FileUtils.cleanDirectory(new File(getTempDirPath()));
|
||||||
|
log.debug("Directory content cleared.");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String processUploadedFile(MultipartFile file, String uploaderIp) {
|
||||||
|
|
||||||
String fileId = fileIdService.generateNewUniqueId();
|
String fileId = fileIdService.generateNewUniqueId();
|
||||||
|
|
||||||
@ -58,30 +76,18 @@ public class FileService {
|
|||||||
try {
|
try {
|
||||||
Files.write(path, file.getBytes());
|
Files.write(path, file.getBytes());
|
||||||
log.debug("File " + file.getOriginalFilename() + " written to " + path.getFileName());
|
log.debug("File " + file.getOriginalFilename() + " written to " + path.getFileName());
|
||||||
|
return fileId;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a folder
|
public File getFileById(String fileId) {
|
||||||
@PostConstruct
|
return new File(getTempDirPath() + File.separator + fileId);
|
||||||
public void createFolder() {
|
|
||||||
Path path = Paths.get(getTempDirPath());
|
|
||||||
log.debug("Checking temp file directory " + path.getFileName());
|
|
||||||
try {
|
|
||||||
if (!Files.exists(path)) {
|
|
||||||
Files.createDirectory(path);
|
|
||||||
log.debug("Directory created");
|
|
||||||
} else {
|
|
||||||
log.debug("Directory already exists. Clearing content.");
|
|
||||||
FileUtils.cleanDirectory(new File(getTempDirPath()));
|
|
||||||
log.debug("Directory content cleared.");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getTempDirPath() {
|
private String getTempDirPath() {
|
||||||
return System.getProperty("user.dir") + tempDirPath;
|
return System.getProperty("user.dir") + tempDirPath;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user