Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1408 Prikazi

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
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
sep. 24
1305
2
jul. 24
1292
2
mar. 24
3501
0
avg. 21
3121
0
jul. 18
4126