Skip to main content
Solved

Downloading a file through an API


Forum|alt.badge.img+1

Hi there,

 

We would like to know if its possible to download a pdf file (or convert it to base64) through an api. Sadly the API only gives the PDF file instead of a base64 encoded string.

 

If abose is possible. Please explain how. Because we dont know where to start even.

 

Results :

Preferred method : Save it as base64

Optional and not preferred : Save the file on our own server.

Must have : Displayable on our own application

Best answer by Anthony

Never mind. I fixed the whole issue. Just inserting the binary into a binary column was the trick.

 

Thanks anyways

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

6 replies

Forum|alt.badge.img+1
  • Author
  • Sidekick
  • 13 replies
  • June 28, 2023

Let me clarify some more. The response of that API gives an octet-stream (lots of binary code and in more precise words. a Byte stream)


Anne Buit
Community Manager
Forum|alt.badge.img+5
  • Community Manager
  • 637 replies
  • June 29, 2023

Hi Anthony,

You can use an HTTP connector process action to retrieve the PDF file and use a subsequent Download file process action to let the user download the file.

If you want to store the file in the meanwhile, you can use a Write File connector.

Converting the file to base64 can be done via logic.

-- These are process flow parameters:
declare @binary_file varbinary(max) = 0xC290CAB59C869D41AB86DDB886204EF4
declare @base64_value varchar(max)

select @base64_value = base64_value
from openjson(
    (
        select base64_value
        from (select @binary_file as base64_value) T
        for json auto
    )
) with (
    base64_value varchar(max)
)

-- Clear the binary file
set @binary_file = null

-- The variable is now converted
select @binary_file, @base64_value

I hope this helps.


Forum|alt.badge.img+1
  • Author
  • Sidekick
  • 13 replies
  • July 3, 2023

Allright, I`m gonna give this a try. Trying to keep you posted


Forum|alt.badge.img+1
  • Author
  • Sidekick
  • 13 replies
  • July 4, 2023

Right, so a new issue has occured. Whenever I am calling to that API. It gives me nothing back. And one of the probable causes might be the headers.

 

Error: 

Process action "buildsimple_api_fetch_document_download" in processflow "api_get_builsimple_purchase_invoice_details" in application 99 returned the following message: "Unable to parse json for \"headers\" input parameter.
Error: After parsing a value an unexpected character was encountered: \". Path '[1].Key', line 8, position 0." (86be518d)

 

This is what we pass in our HTTP connector header

[

    {

        "Key": "X-Tenant-Id",

        "Value": "X"

    },

    {

        "Key": "Authorization",

        "Value": "X"

    },

    {

        "Key": "Accept",

        "Value": "application/octet-stream"

    }

]

 

Some crucial information has been replaced by X of course. But the authorization works as we tested this with also HTTP connectors.

 


Forum|alt.badge.img+1
  • Author
  • Sidekick
  • 13 replies
  • July 5, 2023

Never mind regarding the above. I managed to fixed the headers. Which was not the problem. Im do now have a new challange.

 

I`m currently using postman to see the result of converting a binary/octet-stream to base64 and this is where my problem is starting.

 

The result of pastman base64 character count is approx ~30.000+ characters while the code I am using above can only hold up to 4000 characters. How do I solve this issue?


Forum|alt.badge.img+1
  • Author
  • Sidekick
  • 13 replies
  • Answer
  • July 5, 2023

Never mind. I fixed the whole issue. Just inserting the binary into a binary column was the trick.

 

Thanks anyways


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings