The issue was with the axios instance.

I have added response type to the request header, the issue was solved.

        responseType: "blob",

this was the root cause. After that I was able to download the file with response provided by 'Klian' in the comments to my question.

Answer from Nabeel Mhd on Stack Overflow
🌐
Oracle
docs.oracle.com › en › cloud › paas › content-cloud › rest-api-documents › op-documents-api-1.2-files-fileid-data-get.html
REST API for Documents - Download File
November 27, 2023 - GET .../files/D34A657B8723A96097F80926T0000000000100000001/data?version=2 ... The following example downloads version 1 of the specified file. If the status code indicates success (200), the response includes a data stream that contains the file contents.
🌐
Reddit
reddit.com › r/nextjs › is there a 'best practice' for downloading files from an api response?
r/nextjs on Reddit: Is there a 'best practice' for downloading files from an API response?
November 6, 2023 -

I'm working with an API res that contains a zip, csv, and pdf. I've been researching how I should download and/or create download buttons for these files but a lot of articles I'm looking through specify that their method is 'hacky' (or something similar).

I don't like the idea of pushing a 'hacky' solution to production. It may be a starting point but not really a good foundation to build off of. Does anybody know of good practices for this kind of procedure?

I've boiled it down to:

  1. Parse the response

  2. Store the file contents

  3. Create sources for the downloads

but surely it isn't that simple, right?

🌐
IBM
ibm.com › docs › en › blueworks-live
FileDownload API
Use this resource to download a file that is attached to a process, an instance, or a comment.
🌐
Zoho
zoho.com › creator › help › api › v2.1 › download-file.html
Download File - API v2.1 | Zoho Creator Help
Copiedimport requests api_headers = { "Authorization": "Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf" } try: response = requests.get("https://www.zohoapis.com/creator/v2.1/data/jason18/zylker-store/report/Inventory_Report/3888834000000114050/Product_Manual/download", headers=api_headers) except: print("Exception while making the API request.") This sample request will download the file present in the Product_Manual field of the record with ID 3888834000000114050, which is displayed in the Inventory Report of the Zylker Store application.
🌐
Box
developer.box.com › reference › get-files-id-content
Download file - Box Dev Docs
curl -i -L -X GET "https://api.box.com/2.0/files/12345/content" \ -H "authorization: Bearer <ACCESS_TOKEN>" ... This endpoint is in the version 2024.0. No changes are required to continue using it. For more details, see Box API versioning.Learn more about Box SDK versioning strategy. ... The access token received from the authorization server in the OAuth 2.0 flow. ... The byte range of the content to download.
🌐
CodeSignal
codesignal.com › learn › courses › efficient-api-interactions-with-scala › lessons › downloading-files-from-an-api-using-requests-scala
Downloading Files from an API | CodeSignal Learn
GET requests are fundamental for retrieving files from an API. When you send a GET request using requests.get, your client communicates with the server at a specified URL, asking it to provide the file. The server responds with the file data, if available and permissible, along with an HTTP status code (like 200 OK). Here's a basic example of downloading a file named welcome.txt from our API at http://localhost:8000/notes.
Find elsewhere
🌐
CodeBurst
codeburst.io › download-files-using-web-api-ae1d1025f0a9
Download Files using Web API. How to return a file from an API… | by Changhui Xu | codeburst
February 24, 2021 - In this article, I will use a demo Web API application in ASP.NET Core to show you how to transmit files through an API endpoint. In the final HTML page, end users can left-click a hyperlink to download the file or right-click the link to choose ...
🌐
Medium
medium.com › @khushbooverma8319 › download-api-file-in-frontend-91bd51e4ee19
Download file in frontend getting from API | by Khushbooverma | Medium
May 22, 2023 - Suppose we have a button on click of which we want to download the CSV file. We have a onClick handler named handlDownload as shown below. const handleDownload = () => { setLoading(true); API.get('https://sample/api', { responseType: "blob", }) .then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); console.log(url); var blob = new Blob([response.data], { type: "text/plain;charset=utf-8", }); saveAs(blob, `${response.fileName}.pdf`); setLoading(false); }) .catch((err) => { console.log(err); setLoading(false); }); };
🌐
CodeSignal
codesignal.com › learn › courses › efficient-api-interactions-with-javascript › lessons › downloading-files-from-an-api-using-javascript
Downloading Files from an API Using JavaScript
GET requests are fundamental for retrieving files from an API. When you send a GET request using fetch, your client communicates with the server at a specified URL, asking it to provide the file. The server responds with the file data, if available and permissible, along with an HTTP status code (like 200 OK). Here's a basic example of downloading a file named welcome.txt from our API at http://localhost:8000/notes.
🌐
Postman
postman.com › api-evangelist › box › request › vesg2u5 › download-file
Download file | Box Platform API
I am the API Evangelist, making sense of the technology, business, policies, and the people of APIs since 2010 by surveying and assessing the public and private API landscape
🌐
Zoho
zoho.com › creator › help › api › v2 › download-file.html
Download File - API v2 | Zoho Creator Help
Copiedcurl "https://creator.zoho.com/api/v2/jason18/zylker-store/report/Inventory_Report/3888834000000114050/Product_Manual/download" -X GET -H 'Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf' -H 'environment: development' If the request is a success, the target file will be downloaded.
🌐
Backendless
backendless.com › docs › rest › files_file_download.html
File Download - Backendless REST API Documentation
Downloading a file from the Backendless file storage is the basic HTTP GET operation. The operation should use the same URL which Backendless returned as the result of the file upload operation.
🌐
Google
developers.google.com › google workspace › google drive › download and export files
Download and export files | Google Drive | Google for Developers
To download a blob file stored on Drive, use the files.get method with the ID of the file to download and the alt system parameter. The alt=media parameter tells the server that a download of content is being requested as an alternative response ...