Это код, который, кажется, открывает его из контроллера:
openFile(contentType, field) {
return this.dataUtils.openFile(contentType, field);
}
, а в HTML это используется при передаче данных от объекта, возвращенного службой, например:
<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>
Моя цель состоит в том, чтобы я загружал файл, и при его загрузке он содержит имя файла, а не download(1)
или download(2)
, а в windows он использует некоторые случайные идентификаторы (не связанные с fileID). Мне бы хотелось, чтобы загруженный файл мог быть легко найден пользователем. Я попытался добавить заголовок content-filename. Но я не смог разобрать и установить. Похоже, встроенный сервис Jhipsters data-utils.service.ts
контролирует функциональность загружаемого файла. который выглядит так внутри узловых модулей:
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;
/**
* Method to find the byte size of the string provides
*/
byteSize(base64String: string): string;
/**
* Method to open file
*/
openFile(contentType: string, data: string): void;
/**
* Method to convert the file to base64
*/
toBase64(file: File, cb: Function): void;
/**
* Method to clear the input
*/
clearInputImage(entity: any, elementRef: ElementRef, field: string, fieldContentType: string, idInput: string): void;
/**
* Sets the base 64 data & file type of the 1st file on the event (event.target.files[0]) in the passed entity object
* and returns a promise.
*
* @param event the object containing the file (at event.target.files[0])
* @param entity the object to set the file's 'base 64 data' and 'file type' on
* @param field the field name to set the file's 'base 64 data' on
* @param isImage boolean representing if the file represented by the event is an image
* @returns a promise that resolves to the modified entity if operation is successful, otherwise rejects with an error message
*/
setFileData(event: any, entity: any, field: string, isImage: boolean): Promise<any>;
/**
* Method to download file
*/
downloadFile(contentType: string, data: string, fileName: string): void;
private endsWith;
private paddingSize;
private size;
private formatAsBytes;
}
Будем благодарны за любые указания и советы!