Skip to content

Commit

Permalink
fix: paths
Browse files Browse the repository at this point in the history
  • Loading branch information
oproprioleonardo committed Sep 25, 2024
1 parent cd1b30d commit 4d10ab0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
@Getter
public enum FileContextType {

EVENT("/events"),
USER("/users"),
EMAIL("/emails");
EVENT("events/"),
USER("users/"),
EMAIL("emails/");

private final String path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

@Component
Expand All @@ -24,20 +22,21 @@ public class LocalFileStorage implements IFileStorage {
private String uploadDir;

private Path getUploadDir() {
final Path path = Paths.get(rootPath + File.separator + uploadDir);
final Path path = rootPath.resolve(uploadDir);
if (Files.notExists(path)) {
try {
Files.createDirectories(path);
} catch (IOException e) {
log.error("Não foi possível criar o diretório de upload de arquivos", e);
}
}
return path;
return path.toAbsolutePath();
}

public boolean uploadFile(FileContextType contextType, String filename, byte[] aContent, String... extraPath) {
try {
final Path path = extraPath.length > 0 ? this.getUploadDir().resolve(contextType.getPath()).resolve(String.join("/", extraPath)) : this.getUploadDir().resolve(contextType.getPath());
final Path dir = this.getUploadDir();
final Path path = extraPath.length > 0 ? dir.resolve(contextType.getPath()).resolve(String.join("/", extraPath)) : dir.resolve(contextType.getPath());
if (Files.notExists(path)) Files.createDirectories(path);
Files.write(path.resolve(filename), aContent);
return true;
Expand Down

0 comments on commit 4d10ab0

Please sign in to comment.