Issue
I'm using Jhipster and Jhipster generate a function to open file in browser. The problem is: I don't understand so much the function, and I don't know why, when the file is a CSV file, the file is not opened in the browser but downloaded. It works for other file, like XML, but not for CSV.
Here the code :
openFile(data: string, contentType: string | null | undefined): void {
contentType = contentType ?? '';
const byteCharacters = atob(data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], {
type: contentType,
});
const fileURL = window.URL.createObjectURL(blob);
const win = window.open(fileURL);
win!.onload = function () {
URL.revokeObjectURL(fileURL);
};
}
If anyone has an idea, It will be really helpful. Thanks !
Solution
My solution was to create a new route /csv-view (the button redirect on this route) and transform the content in a array of strings and then a html table.
Answered By - Collembole
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.