Problems extracting an image from the database

12 views
Skip to first unread message

rdvg...@gmail.com

unread,
May 18, 2021, 8:49:05 PM5/18/21
to CodenameOne Discussions
Hi,

I'm trying to get an image from the database and I can't get the "ConnectionRequest" API to run (I see the webservice in debug mode and nothing moves). It's frustrating because I was able to upload the image without a problem, but I can't download it.

My code on the client:

public static void fetchFoto(SuccessCallback<Image> callback) {
        fetchFoto(usr.usuarioId.getLong(), callback);
    }

public static void fetchFoto(long usuarioId, SuccessCallback<Image> callback) {
        ConnectionRequest cr = new ConnectionRequest(SERVER_URL + "usuario/foto/" + usuarioId, false);
        cr.setFailSilently(true);
        cr.downloadImageToStorage("fotoImagen-" + usuarioId, callback);
    }

My code in the webservice

    
    @RequestMapping(value = "/foto/{usuarioId:.+}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getFoto(@PathVariable("usuarioId") Long usuarioId) {
        byte[] av = usuarios.getFoto(usuarioId);
        if(av != null) {
            return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(av);
        }
        return ResponseEntity.notFound().build();
    }


    public byte[] getFoto(Long usuarioId) {
        Usuario u = usuarios.findOne(usuarioId);
        return u.getFoto();
//        return obtenImagenByte(u.getFoto());
    }


The variable SERVER_URL has the local address of the server and I rule out that it is wrong since it is used for all other connections to the server.

I must also clarify that I can see that the routine in the client is executed, but as I mentioned in the webservice the execution never arrives.

Shai Almog

unread,
May 18, 2021, 10:32:56 PM5/18/21
to CodenameOne Discussions
What do you see in the network monitor in the simulator?
Notice that downloadImageToStorage won't do anything if the image is already downloaded!
That's the idea, it's smart enough to know that the image is already there and just send you the existing image. You can delete it from the ".cn1" directory to debug.
Reply all
Reply to author
Forward
0 new messages