dev
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-01-27 20:27:39 +07:00
parent cf2f73955b
commit 4a185e6f9a
12 changed files with 185 additions and 21 deletions
@@ -0,0 +1,36 @@
package ru.soune.nocopy.service.file;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.configuration.file.FileStorageConfig;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@Service
@Slf4j
public class FileStorageService {
@Autowired
private FileStorageConfig storageConfig;
public Resource loadFileAsResource(String filePath) throws IOException {
Path path = Paths.get(storageConfig.getBasePath()).resolve(filePath).normalize();
Resource resource = new UrlResource(path.toUri());
if (!resource.exists()) {
throw new FileNotFoundException("File not found: " + filePath);
}
if (!resource.isReadable()) {
throw new IOException("File is not readable: " + filePath);
}
return resource;
}
}