Rev 200 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 200 | Rev 204 | ||
|---|---|---|---|
| Line 20... | Line 20... | ||
| 20 | import org.primefaces.model.CroppedImage; |
20 | import org.primefaces.model.CroppedImage; |
| 21 | import org.primefaces.model.DefaultStreamedContent; |
21 | import org.primefaces.model.DefaultStreamedContent; |
| 22 | import org.primefaces.model.StreamedContent; |
22 | import org.primefaces.model.StreamedContent; |
| 23 | import org.springframework.context.annotation.Scope; |
23 | import org.springframework.context.annotation.Scope; |
| 24 | 24 | ||
| - | 25 | import br.com.ec.core.util.TipoExtensao; |
|
| 25 | import br.com.ec.core.util.VerificadorUtil; |
26 | import br.com.ec.core.util.VerificadorUtil; |
| 26 | import br.com.ec.domain.util.ConversorUtil; |
27 | import br.com.ec.domain.util.ConversorUtil; |
| 27 | 28 | ||
| 28 | @Named |
29 | @Named |
| 29 | @Scope("view") |
30 | @Scope("view") |
| Line 77... | Line 78... | ||
| 77 | public StreamedContent getImage() throws IOException { |
78 | public StreamedContent getImage() throws IOException { |
| 78 | if(VerificadorUtil.estaNulo(bytes)) { |
79 | if(VerificadorUtil.estaNulo(bytes)) { |
| 79 | File file = new File("c://usuario.png"); |
80 | File file = new File("c://usuario.png"); |
| 80 | bytes = ConversorUtil.converterFileParaBytes(file); |
81 | bytes = ConversorUtil.converterFileParaBytes(file); |
| 81 | }
|
82 | }
|
| 82 | - | ||
| 83 | DefaultStreamedContent defaultStreamedContent = new DefaultStreamedContent(new ByteArrayInputStream(bytes), "image/png", "teste.png"); |
- | |
| - | 83 | DefaultStreamedContent defaultStreamedContent = DefaultStreamedContent.builder() |
|
| - | 84 | .contentType(TipoExtensao.PNG.getDescricao()) |
|
| - | 85 | .name("teste.png") |
|
| - | 86 | .stream(() -> new ByteArrayInputStream(bytes)).build(); |
|
| 84 | return defaultStreamedContent; |
87 | return defaultStreamedContent; |
| 85 | }
|
88 | }
|
| 86 | 89 | ||
| 87 | public void fileUploadAction(FileUploadEvent event) { |
90 | public void fileUploadAction(FileUploadEvent event) { |
| 88 | try { |
91 | try { |
| Line 93... | Line 96... | ||
| 93 | String realPath = context.getRealPath("/"); |
96 | String realPath = context.getRealPath("/"); |
| 94 | 97 | ||
| 95 | File file = new File(realPath + "/imagens/temp/"); |
98 | File file = new File(realPath + "/imagens/temp/"); |
| 96 | file.mkdirs(); |
99 | file.mkdirs(); |
| 97 | 100 | ||
| 98 | byte[] arquivo = event.getFile().getContents(); |
- | |
| - | 101 | byte[] arquivo = event.getFile().getContent(); |
|
| 99 | String caminho = realPath + "/imagens/temp/" + event.getFile().getFileName(); |
102 | String caminho = realPath + "/imagens/temp/" + event.getFile().getFileName(); |
| 100 | setCurrentImageName(event.getFile().getFileName()); |
103 | setCurrentImageName(event.getFile().getFileName()); |
| 101 | 104 | ||
| 102 | FileOutputStream fos = new FileOutputStream(caminho); |
105 | FileOutputStream fos = new FileOutputStream(caminho); |
| 103 | fos.write(arquivo); |
106 | fos.write(arquivo); |