Skip to main content

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

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

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

 


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.


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


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


Reply