Upon receiving a byte[] file from the server containing the content of a file along with its name and content type, I have attempted to download the file using the following JavaScript code:
const link = document.createElement('a');
document.body.appendChild(link);
link.style.display = 'none';
const blobFile = new Blob([content], {type: 'text/plain'});
const url = window.URL.createObjectURL(blobFile);
link.href = url;
link.download = "test.txt";
link.click();
window.URL.revokeObjectURL(url);
Unfortunately, this method downloads a text file with binary content. How can I convert the binary data to the appropriate file type on the client side using JavaScript or Typescript? Thank you for your help!