Ir al contenido
Menú
Se marcó esta pregunta
1342 Vistas

Hi all,

It's my first request here and hope you will be nice with me :).

I would like to use the ODOO API in version 16.

I'm developping in JAVA.

Do you know the way I can read a file from ir.attachment table ?


When I run this kind of code, "db_datas" is always containing the value FALSE.

How can I get the binary (byte[]) of the requested file ?


Thanks a lot for your support.


Nicolas


----------------------


results = asList(

                    (Object[]) client.execute(

                            "execute_kw",

                            asList(

                                    db,

                                    uid,

                                    password,

                                    "ir.attachment",

                                    "search_read",

                                    asList(asList(

                                            asList("id", "=", 4529)

                                    )),

                                    new HashMap() {

                                {

                                    put("fields", asList("id", "name", "res_model", "mimetype", "db_datas"));  

                                }

                            }

                            )

                    )

            );


for (Object obj : results) {

                Map attachment = (Map) obj;

                String filename = (String) attachment.get("name");

                byte[] data = Base64.getDecoder().decode((String) attachment.get("db_datas"));


                try (FileOutputStream fos = new FileOutputStream(filename)) {

                    fos.write(data);

                    System.out.println("Pièce jointe PDF récupérée : " + filename);

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }



Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
sept 24
1242
2
jul 24
1253
2
mar 24
3473
0
ago 21
3097
0
jul 18
4080