文件上传、下载(post)

重点

post请求,提交的参数数据较大,将参数放入body中,格式为FormData
const formData = new FormData();
    prns.forEach(i => {
   
      formData.append('prns', i);
    })
    let request = new HttpRequest("POST", this.url, formData, {
   
      headers: this.jwt(),
      responseType: "blob",
      reportProgress: true
    })

文件上传

  isUploading: Boolean = false;
  customReq = (item: UploadXHRArgs) => {
   
    const formData = new FormData();
    if (this.fileList.length == 0) {
   
      this.message.error('请上传tif文件!');
      return;
    }
    formData.append('files', this.fileList[0]);
    const req = new HttpRequest('POST', this.url, formData, {
   });
    this.isUploading = true;
    return this.http.request(req).pipe(filter(e => e instanceof HttpResponse)).subscribe((raster: HttpResponse<any>) => {
   
      this.isUploading = false;
      if (raster.status == 201) {
   
        this.message.success('文件上传成功!');
        this.fileList = [];
        this.filesDisabled = this.fileList.length == 1;
      } else {
   
        this.message.error('文件上传失败!');
      }
    }, () => {
   
      this.message.error('文件上传失败!');
      this.isUploading = false;
    })
  };

文件下载

<button nz-button nzType="primary" (click)="partDownload()">批量下载</button>
                <nz-spin [nzSpinning]="isSearch || isDownload" [nzIndicator]="indicatorTemplate">
                    <yz-ngx-grid #grid [settings]="settings" [source]="source" (onBaGridReady)="onBaGridReady($event)">
                    </yz-ngx-grid>
                </nz-spin>
                <ng-template #indicatorTemplate>
                    <div style="width: 100%;height:100%;background-color: rgba(255,255,255,0.6);"<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值