Here is the snippet of code responsible for opening the file from the controller:
openFile(contentType, field) {
return this.dataUtils.openFile(contentType, field);
}
Within the HTML, this function is used to pass in data retrieved from a service object. Take a look at how it's implemented below:
<button type="submit" (click)="openFile(dataCleansing.fileContentType, dataCleansing.uploadedFileContent)"
class="btn btn-info viewTheme">
<fa-icon [icon]="'download'"></fa-icon>
<fa-icon> <span> Open/View File</span>
</button>
The main goal here is to ensure that when the file is downloaded, it retains its original filename instead of being saved as 'download(1)' or 'download(2)' on Windows. This makes it easier for users to locate the downloaded file. I've attempted to include a header content-filename but ran into issues parsing and setting it properly. It appears that the download functionality is controlled by Jhipster's built-in service called 'data-utils.service.ts' located within the node modules:
import { ElementRef } from '@angular/core';
/**
* An utility service for data.
*/
export declare class JhiDataUtils {
constructor();
/**
* Method to abbreviate the text given
*/
abbreviate(text: string, append?: string): string;
.
. // Other utility methods omitted for brevity
.
}
Any advice or suggestions on how to achieve the desired functionality would be greatly appreciated!