34
Views
6
Comments
Solved
How to download pdf with specific url like www.abc.com/abc
Application Type
Reactive

Hi,

I need to load a PDF file generated by another system to display it on the web. Normally, we can access or download the file through a URL, for example, www.abc.com/abc.pdf. But in my case, I have a special URL generated by another system to display, for instance, www.abc.com/abc. The question is, how can I create a function to download the file from the above URL?

UserImage.jpg
Phongsakorn.P
Solution

Finally, I found the solution using the GetRequest_Submit action from the HTTPRequestHandler extension.

2021-11-12 04-59-31
Manikandan Sambasivam

Hi,

You can read the file from www.abc.com/abc, convert it to Base64 format, and store it in an OutSystems entity. Once stored, you can retrieve the file from the entity and provide it as a downloadable file whenever needed.


2019-01-07 16-04-16
Siya
 
MVP

If the URL www.abc.com/abc is publicly accessible, you can use JavaScript to download the file directly on the client side.

UserImage.jpg
Rounak Rawat

Hii @Phongsakorn.P,

You can add the following JavaScript code to trigger the download or display of the file in a new browser tab or window:

window.open('https://www.abc.com/abc', '_blank');

Hope it helps you.

Regards,

Rounak Rawat

2024-07-12 05-57-50
Gourav Shrivastava
Champion

Hello @Phongsakorn.P 

o handle downloading and displaying a PDF file from a special URL (e.g., www.abc.com/abc), you can make an HTTP GET request using REST API to fetch the file. Ensure the response has the Content-Type set to application/pdf. Once you retrieve the file as binary data, you can either store it temporarily or directly pass it to the front end for display.


For PDF view you can use PDF Viewer Reactive.

Thanks

Regards

Gourav Shrivastava

2024-07-12 05-57-50
Gourav Shrivastava
Champion

And if you want to do this js code you can take reference also you can modify :-

  1. async function PDFBYURL(url) {
  2.     try {
  3.         // Send a GET request to the URL
  4.         const response = await fetch(url, {
  5.             method: 'GET',
  6.             headers: {
  7.                 'Content-Type': 'application/pdf', // Specify that we expect a PDF
  8.             },
  9.         });
  10.         // Check if the response is successful
  11.         if (response.ok) {
  12.             // Convert the response into binary data
  13.             return await response.arrayBuffer();
  14.         } else {
  15.             throw new Error(`Error fetching PDF: ${response.status} - ${response.statusText}`);
  16.         }
  17.     } catch (err) {
  18.         console.log('Failed to fetch the PDF:', err);
  19.         return null;
  20.     }
  21. }



Thanks

Regards

Gourav Shrivastava


 

UserImage.jpg
Phongsakorn.P
Solution

Finally, I found the solution using the GetRequest_Submit action from the HTTPRequestHandler extension.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.