Solved

download PDF from an API in a button

  • 6 June 2023
  • 4 replies
  • 167 views

Userlevel 3
Badge +1

I have an API that returns a PDF file in the content 

is there a way that i can make a button that consumes this api and return the file in the browser to be downloaded ?

the PDF file is big so i will need to await it

icon

Best answer by abdallaahmed61 7 June 2023, 12:05

View original

4 replies

Userlevel 6
Badge +3

If you downloaded the file into a MemoryStream, you can use this code:

throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);

 

Userlevel 3
Badge +1

If you downloaded the file into a MemoryStream, you can use this code:

throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);

 

this may solve the second problem 
but i still need to fix the first problem which is, i cant make the button async to wait the api call.

Userlevel 3
Badge +1

i solved the problem by using Task.Run and Task.Wait
and used the 
throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);
that zfebert56 mentioned

Userlevel 7
Badge

Thank you for sharing your solution with the community @abdallaahmed61 !

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved