Skip to main content
10-Marble
August 10, 2023
Question

Is it possible to create a file download function?

  • August 10, 2023
  • 1 reply
  • 878 views

I tried to create a function to download local storage information in a file but it did not work.
I have tried the following

 

 const fileName = "maintenance.csv";
 const fileContent = $scope.jsonToCsv(localStorage.getItem('records'));
 const blob = new Blob([fileContent], { type: "application/octet-stream" });
 const url = window.URL.createObjectURL(blob);
 const fileLink = document.querySelector('.file-link')
 fileLink.setAttribute("href", url);
 fileLink.setAttribute("download", fileName);
 fileLink.click()
 window.URL.revokeObjectURL(url);

 

This function is executed when the "file" widget with the class "file-link" is clicked.
However, while the file is downloaded in the preview, it does not work on iOS.
Please let me know if you know how to make the file downloadable.
Looking forward to hearing from you.

 

1 reply

16-Pearl
August 21, 2023

View does not allow JS access to device for security reasons