Image upload with Spring and UIkit

0

Dear implementing upload in my project, I was guided by the Algaworks Brewer project (uploads the beer photo), using a front-end framework UIkit The upload is being done, so I can see that in a folder with the name "null" is serving as the location where the files are stored, there is something very strange happening and I can not say the reason.

First of all the image of the file that was uploaded is not appearing and I realize the 404 error is occurring in a GET, secondly I noticed that a folder is created inside the project folder only with the name null, when it should be the photo folder

I understand that it is not very clear what I described more if someone who uses these technologies can comment

The project makes use of SpingBoot, Thymeleaf and Bootstrap

    
asked by anonymous 19.07.2017 / 00:46

1 answer

0

I also went through this problem, when 404 is that spring is not finding the folder path to save the photo, make sure the app actually created the folder inside projeto project/.null/nomePasta . I advise you to do it differently instead of creating the folder inside the project you can create it out of the project, you will probably compile the project and run it in tomcat , when compiled it generates a project.war where are the compiled files of the app.

Here is an example I used in my app to create the photos folder outside the app:

@Profile("local")
@Component
public class LogoPath {

private static final Logger logger = LoggerFactory.getLogger(LogoPath.class);

private Path local;

public static Path getDefaultPath() {
    //Servidor linux
    Path pathDefault = Paths.get("/app/fotos");
    if(Files.notExists(pathDefault, LinkOption.NOFOLLOW_LINKS)) {
        //No usuario do windows
        String userHome = System.getProperty("user.home");
        pathDefault = Paths.get(userHome, "fotos");
    }
    return pathDefault;
}

public LogoPath() {
    this(getDefaultPath());
}

public LogoPath(Path path) {
    this.local = path;
    criarPastas();
}

private void criarPastas() {
    try {
        Files.createDirectories(this.local);

        if(logger.isDebugEnabled()) {
            logger.debug("Pasta criada para salvar arquivos.");
            logger.debug("Pasta default: " + this.local.toAbsolutePath());
        }
    } catch (IOException e) {
        throw new RuntimeException("Erro criando pasta para salvar arquivos.", e);
    }

}

}
    
19.09.2017 / 13:25