首页 > 解决方案 > ngx-filesaver 如何控制文件的保存位置?

问题描述

filesaver 从我的输入文本中保存文件,如下所示:

组件.ts

  constructor(private _httpClient: HttpClient, 
    private _FileSaverService: FileSaverService,
    private exportAsService: ExportAsService) { }

public text ="";
  public fileName: string;
  onDown(type: string, fromRemote: boolean) {
    const fileName = `save.${type}`;
    if (fromRemote) {
      this._httpClient.get(`assets/files/demo.${type}`, {
        observe: 'response',
        responseType: 'blob'
      }).subscribe(res => {
        this._FileSaverService.save(res.body, fileName);
      });
      return;
    }
    const fileType = this._FileSaverService.genType(fileName);
    const txtBlob = new Blob([this.text], { type: fileType });
    this._FileSaverService.save(txtBlob, fileName);
  }

组件.html

<div class="form-outline" id="mytable">
    <textarea [(ngModel)]="text" class="form-control" id="textAreaExample2" rows="15" placeholder="Write a Test Case"></textarea>
  </div>


  <label>Your Test: </label>
  <div class="row"   id='display'>
    {{text}}
  </div>
  <button (click)="onDown('robot', false)"  type="button"  class="btn btn-success float-right">Add</button>

我想知道是否有可能控制文件的确切存储位置,而无需在单击“添加”按钮时询问我下载文件的位置

因此,例如,当我单击“添加”按钮时,我希望始终将文件下载到“D:”文件夹而不询问我

标签: angulartypescriptngx-bootstrap

解决方案


推荐阅读