Não estou conseguindo salvar o meu arquivo no servidor.
package br.com.casadocodigo.loja.infra;
import java.io.File;
import java.io.IOException;
import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@Component
public class FileSaver {
@Autowired
private HttpServletRequest request;
public String write(String pastaBase, MultipartFile file) {
try {
//String realPath = request.getServletContext().getRealPath("/" + pastaBase);
//String pathname = realPath + "/" + file.getOriginalFilename();
String homePath = System.getProperty("user.home");
String baseFolderPath = homePath + "/" + pastaBase;
String path = baseFolderPath +"/" +file.getOriginalFilename();
file.transferTo(new File(path));
return pastaBase + "/" + file.getOriginalFilename();
} catch (IllegalStateException | IOException e) {
throw new RuntimeException(e);
}
}
}
FileServer.class
package br.com.casadocodigo.loja.conf;
import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServeletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { AppWebConfigurattion.class, JPAConfiguration.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter trataFiltro = new CharacterEncodingFilter();
trataFiltro.setEncoding("UTF-8");
return new Filter[] { trataFiltro };
}
@Override
protected void customizeRegistration(Dynamic registration) {
registration.setMultipartConfig(new MultipartConfigElement(""));
}
}
Servelet.class
`