Doubt with Vraptor Image Download

2
Hello everyone, I have a question about the Vraptor Download function, I have an IMG on my server and I try to display it in my Mobile Application but when I make the request to the server it does not return an IMG type response (type="image / jpg" is not error in the request when I call the Werb service me returns status 200.

If anyone has an idea, they can help me.

 @Get
public Download foto(String foto) throws FileNotFoundException {
    File file = new File("C:\Users\Gabriel\Portifolio\src\main\webapp\WEB-INF\upload\"+foto);
    String contentType = "image/jpg";
    String filename = foto;

    return new FileDownload(file, contentType, filename);

}

Code in my function for Downloading Images.

    
asked by anonymous 04.12.2015 / 18:38

1 answer

0

Good afternoon Darlan Oliveira, I'm new here, but I think I can help you. In my project I made a Controller to manage my images and this is a code that I did.

@Open
@Get
@Path("/formaPagamento")  
public Download imagemFormaPagamento(String id) {  
    File file = new File(NomenclaturaArquivo.getImagemFormaPagamento() + id);

    String contentType = "image/png";
    String filename = id + ".png";

    try {
        return new FileDownload(file, contentType, filename);
    } catch (FileNotFoundException e) {
        System.out.println("erro: " + e);
        return null;
    }
}

And I call it in my JSP like this:

<img src="<c:url value='/imagem/formaPagamento?id=${f.id }'/>">

In my controller I use an annotation to define as an image.

@Controller
@Path("/imagem")
public class ImagemController {

The @Open annotation is one that I created to let the code be accessed without having to be logged into the system, so disregard.

I really do not know if it helps, but maybe you're doing something different. These are parts of my code working, step by step. There in Filename, it's a class that has constants that take my folders from the server. So I find it quieter to work on and make future path modifications, rather than crashing into the source code. Of course this goes from programmer to programmer.

I also had a lot of trouble finding my images in the folder .... Generally the JSP call was correct and only my file was not found because I was using linux. I did in the case a simple main class, trying to find this file and returning a (FileNotFoundException) until I found the correct way to find my image. Yes, I did the routine for the JSP. So I think it's easier to test without having to run on the server.

I do not know if I helped you, but my contribution is still there.

    
23.12.2015 / 22:12