Rest API - How Get File From Attachment

416 views
Skip to first unread message

Rezky

unread,
Sep 18, 2023, 3:24:13 AM9/18/23
to iDempiere
Hi Everyone,
Is there a way to retrieve files via Rest API ?
I haven't found any documentation regarding attachments in the Rest API.

If the data provided is binary data based, how can I convert it into a PDF file either for reading or for downloading.

Thank you for your help.

Regards,
Rezky

Diego Ruiz

unread,
Sep 18, 2023, 6:37:51 AM9/18/23
to iDempiere
Hi Rezky,

There are three ways to retrieve files with the REST API, depending on which file you want to get.

1 - Get attachments from a record

  • .../api/v1/models/{tablename}/{id}/attachments -> get all attachments from the record id of the given table
  • .../api/v1/models/{tablename}/{id}/attachments/zip -> get all attachments from the record id of the given table in a zip file
  • .../api/v1/models/{tablename}/{id}/attachments/{filename} -> get the content of attachment with the filename from the record id of the given table
2 - Get the print format from the model's record ID. It returns the file that you get when you click print on the WebUI
  • .../api/v1/models/{tablename}/{recordId}/print
3 - Get a file content
  • .../api/v1/files/{fileName}?length={processFileLength}&nodeId={processNodeId}

Regarding the conversion of the result to PDF. It depends on the language you're using to request the file. You can google How to convert Base64 to File in ...

Best regards,
Diego

Rezky

unread,
Sep 19, 2023, 12:14:41 AM9/19/23
to iDempiere
Hi Diego,
I really appreciate your help.
Referring to your solution, I would like to explain what steps I have taken below, in order to explain the problem I am facing.

(Note : I am using Rest API with Version 0.1.0.202211181521)
- .../api/v1/models/{tablename}/{id}/attachments ->  The information provided is the file name and type, there is no binary data that I can convert into a file.
Capture.PNG

-  .../api/v1/models/{tablename}/{id}/attachments/{filename} -> Not Acceptable, Are there any steps or requirements that I missed?
Capture.PNG

Then I looked for another way by accessing the attachment table. 
-  .../api/v1/models/AD_Attachment -> I got the record, and I found binary data.
Capture.PNG
However, when I tried to decode the binary data, I only got the file directory path in XML format like this.
<?xml version="1.0" encoding="UTF-8"?><attachments><entry file="%ATTACHMENT_FOLDER%1000003\0\259\1004913\Export_C_InvoiceLine.pdf" name="Export_C_InvoiceLine.pdf"/></attachments>

What makes me confused is how to obtain a physical file that I can download or view, whether the data obtained is in the form of Binary Data which can be decoded as I once tried for an Image file on a form, via the Rest API service.
Thank You,

Regards,
Rezky

Carlos Antonio Ruiz Gomez

unread,
Sep 19, 2023, 9:08:15 AM9/19/23
to idem...@googlegroups.com
Hi Rezky,

I just did tests with local master (release-11) and demo.globalqss.com (release-10) and both worked fine.

You can try in your postman like:

It works perfect from postman.

Maybe your headers are different?  Check against the postman examples.

Regards,

Carlos Ruiz



On 19/9/23 a las 6:14, Rezky wrote:
Hi Diego,
I really appreciate your help.
Referring to your solution, I would like to explain what steps I have taken below, in order to explain the problem I am facing.

(Note : I am using Rest API with Version 0.1.0.202211181521)
- .../api/v1/models/{tablename}/{id}/attachments ->  The information provided is the file name and type, there is no binary data that I can convert into a file.


-  .../api/v1/models/{tablename}/{id}/attachments/{filename} -> Not Acceptable, Are there any steps or requirements that I missed?


Then I looked for another way by accessing the attachment table. 
-  .../api/v1/models/AD_Attachment -> I got the record, and I found binary data.

Message has been deleted

Rezky

unread,
Sep 19, 2023, 11:47:35 AM9/19/23
to iDempiere
I am using File System method as Storage Provider, meanwhile in Garden Admin is using Database Method.
So in AD_Attachment - binary column, instead of actual binary data, it keeps path info of the file in xml format like I mention before:


<?xml version="1.0" encoding="UTF-8"?><attachments><entry file="%ATTACHMENT_FOLDER%1000003\0\259\1004913\Export_C_InvoiceLine.pdf" name="Export_C_InvoiceLine.pdf"/></attachments>

So furher question is the app method for attachment also support for File System method as storage provider?

Carlos Antonio Ruiz Gomez

unread,
Sep 19, 2023, 12:03:48 PM9/19/23
to idem...@googlegroups.com
Yes, I noticed that and tested with both scenarios, DB and FileSystem, both worked fine.

Regards,

Carlos Ruiz


El 19/9/23 a las 17:47, Rezky escribió:

Rezky

unread,
Sep 20, 2023, 9:34:15 AM9/20/23
to iDempiere
Hi Carlos,
Sorry for ask again, for the latest Rest API plugin jar, is it required to use JVM v17? I'm still using JVM v11.
photo_2023-09-20_20-31-50.jpg
Thank You.

Regards,
Rezky

Carlos Antonio Ruiz Gomez

unread,
Sep 20, 2023, 10:09:26 AM9/20/23
to idem...@googlegroups.com
The repository has two branches,

release-10 must be compiled with java 11
master must be compiled with java 17  (I think it probably must compile with java 11 too, but is better to be in sync with the iDempiere core)

Regards,

Carlos Ruiz


On 20/9/23 at 15:34, Rezky wrote:
Hi Carlos,
Sorry for ask again, for the latest Rest API plugin jar, is it required to use JVM v17? I'm still using JVM v11.

ROGER ROMERO

unread,
Nov 17, 2023, 3:36:39 PM11/17/23
to iDempiere

Good afternoon, dear Carlos Ruiz. A pleasure to greet. 
I would like to know if the plugin: com.trekglobal.idempiere.rest.api can be used with the release-9 version of Idempiere?

Is there a tutorial on how to implement it? 
I ask this because in the plugin repository, there is no release-9 branch.

Regards,

Roger Romero

Carlos Antonio Ruiz Gomez

unread,
Nov 18, 2023, 5:56:36 AM11/18/23
to idem...@googlegroups.com
It won't work straight, you can try to fix the broken parts and make it compatible.


Am 17.11.23 um 21:36 schrieb ROGER ROMERO:

ROGER ROMERO

unread,
Nov 18, 2023, 3:15:56 PM11/18/23
to idem...@googlegroups.com
Thank you very much for the response, dear Carlos.

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/53eb35d4-cab2-4859-aa6d-37bdc89cfba2%40gmail.com.

Simon Josue Puyosa Raffoul

unread,
Jul 18, 2024, 4:19:36 PM (9 days ago) Jul 18
to iDempiere

Hello Carlos,

I'm encountering an issue with the API endpoint /api/v1/models/AD_Attachment. Currently, when attempting to use POST or PUT methods to upload a ZIP file (encoded in base64 or as bytes), the binaryData field ends up as null.

Could you assist me in finding a solution? Ideally, I'm looking for a method to successfully send a ZIP containing all attachments either through /api/v1/models/AD_Attachment or perhaps /api/v1/models/{tableName}/{id}/attachments/zip.

Thank you for your help in advance.

Carlos Antonio Ruiz Gomez

unread,
Jul 18, 2024, 6:08:32 PM (9 days ago) Jul 18
to idem...@googlegroups.com
Hi Simon, can you please do a test against demo.globalqss.com and share here the postman (or body) for your failing case?

Regards,

Carlos Ruiz

Simon Josue Puyosa Raffoul

unread,
Jul 19, 2024, 10:34:27 AM (8 days ago) Jul 19
to iDempiere

I actually managed to post the attachment while taking screenshots. However, I'm still facing issues when trying to edit an already created attachment. Initially, I attempted to edit and send it using models/ad_attachments, but in the post, the binaryData in base64 converts to null. I think this might be a bug


photo_2024-07-19_10-29-21.jpg

photo_2024-07-19_10-11-00.jpg


When I attempted a PUT request, it resulted in a 500 error due to issues with editing binaryData. This is also a problem


photo_2024-07-19_09-57-24.jpg
 

Another method I tried was using models/table_name/id/attachments/zip. This approach allowed me to successfully post the attachment.


photo_2024-07-19_10-15-29.jpg
 

Unfortunately, when attempting to edit using this method, I encountered a 405 error indicating that the method is not allowed :(

photo_2024-07-19_10-25-25.jpg

While I can manage with the workaround of deleting and reposting to edit an attachment, it involves making two requests for what should ideally be a single action.

Carlos Antonio Ruiz Gomez

unread,
Jul 20, 2024, 6:27:59 AM (7 days ago) Jul 20
to idem...@googlegroups.com
Can you share here a postman of the failing case against demo.globalqss.com?



On 7/19/24 16:34, Simon Josue Puyosa Raffoul wrote:

I actually managed to post the attachment while taking screenshots. However, I'm still facing issues when trying to edit an already created attachment. Initially, I attempted to edit and send it using models/ad_attachments, but in the post, the binaryData in base64 converts to null. I think this might be a bug





When I attempted a PUT request, it resulted in a 500 error due to issues with editing binaryData. This is also a problem



 

Another method I tried was using models/table_name/id/attachments/zip. This approach allowed me to successfully post the attachment.



 

Unfortunately, when attempting to edit using this method, I encountered a 405 error indicating that the method is not allowed :(



Simon Josue Puyosa Raffoul

unread,
Jul 22, 2024, 11:03:38 AM (5 days ago) Jul 22
to iDempiere
Sure

1. This is the bug where posting to ad_attachment makes binaryData null. You can see it because it does not return a binaryData value:
photo_2024-07-22_10-48-08.jpg

2. This is the bug where ad_attachment does not permit you to modify binaryData:
photo_2024-07-22_10-49-15.jpg

Honestly, I'm okay with working only with url/api/v1/models/{table_name}/{id}/attachments/zip for posting (I did that to demonstrate the next bug). The problem here is that I cannot edit the attachment by updating it with new data.

3. This is the bug where attachments/zip or attachments does not let me modify the data value.
photo_2024-07-22_10-51-09.jpg
Reply all
Reply to author
Forward
0 new messages