Olá pessoal, poderiam me ajudar? Não estou conseguindo exibir a foto que o método save armazenou no S3 da Amazon.
No campo da imagem aparece o link da foto e não a foto (exatamente o caminho que está sendo gravado no BD e o mesmo que consta dentro do bucket do S3 da Amazon)
se clicar no link que aparece no formulário, o retorno em outra pagina exibe 404- not found mas a foto está gravada no bucket do s3
Imagem: https://s3.amazonaws.com/superkovalev/beef.jpg'''
este é o lista.xhtml no campo de exibir a foto
<h:column>
<f:facet name="header">Imagem</f:facet>
<h:outputLink value="#{request.contextPath}
/#{book.summaryPath}">
#{book.summaryPath}
</h:outputLink>
</h:column>
este é o filesaver (só troquei pelas credenciais corretas):
public class FileSaver {
...
public String write(String baseFolder,
Part multipartFile) {
AmazonS3Client s3 = client();
String fileName = extractFilename(multipartFile
.getHeader(CONTENT_DISPOSITION));
try {
s3.putObject("casadocodigo", fileName,
multipartFile.getInputStream(),
new ObjectMetadata());
return "https://s3.amazonaws.com/casadocodigo/"
+fileName;
} catch (AmazonClientException | IOException e) {
throw new RuntimeException(e);
}
}
private AmazonS3Client client() {
AWSCredentials credentials = new BasicAWSCredentials(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
AmazonS3Client newClient =
new AmazonS3Client(credentials,
new ClientConfiguration());
newClient.setS3ClientOptions(new S3ClientOptions()
.withPathStyleAccess(true));
return newClient;
}
este é o adminbooksbean
@Model
public class AdminBooksBean {
private Book product = new Book();
@Inject
private BookDAO productDAO;
private List<String> selectedAuthorsIds = new ArrayList<>();
@Inject
private MessagesHelper messagesHelper;
private Part summary;
@Inject
private FileSaver fileSaver;
public void setSummary(Part summary) {
this.summary = summary;
}
public Part getSummary() {
return summary;
}
@Transactional
public String save(){
populateBookAuthor();
String coverPath = fileSaver.write("summaries", summary);
product.setSummaryPath(summaryPath);
productDAO.save(product);
messagesHelper.addFlash(new FacesMessage("Livro gravado com sucesso"));
return "/livros/list?faces-redirect=true";
}
private void populateBookAuthor() {
selectedAuthorsIds.stream().map( (strId) -> {
return new Author(Integer.parseInt(strId));
}).forEach(product :: add);
}
public void setSelectedAuthorsIds(List<String> selectedAuthorsIds) {
this.selectedAuthorsIds = selectedAuthorsIds;
}
public List<String> getSelectedAuthorsIds() {
return selectedAuthorsIds;
}
public Book getProduct() {
return product;
}
}
classe Book na parte do getter e setter summary
private String summaryPath;
public String getSummaryPath() {
return summaryPath;
}
public void setSummaryPath(String summaryPath) {
this.summaryPath = summaryPath;
}