如何使用POST请求(使用参数和正文)以及ng2-file-upload angular

时间:2019-02-10 17:44:33

标签: javascript angular typescript file-upload

在这里,我要使用“带参数和正文的POST方法”上传一些数据。我知道发布请求,但是到目前为止,我正在使用“ PUT方法”上传下面的请求正文是我的代码

  this.upload= new FileUploader({ url: this.service.dataUpload('/uploadFile'), queueLimit: 999, method: 'PUT' });
    this.upload.onBeforeUploadItem = (item) => {
      debugger;
      item.withCredentials = false;
    };
    //Call back for uploaded
    this.upload.onCompleteItem = (item: any, response: any, status: any, headers: any) => {


         console.log("This is file name::",data['file']['name']);

//It Contains Object
         console.log("data::",this.DataTemplate[data['file']['name']]);

      if(status == 0){

        this.service.saveData(this.DataTemplate[data['file']['name']])
          .subscribe(res => { console.log(res.status); });
        return;
      }


      var responsePath = JSON.parse(response);

      if (status == 201) {


        this.DataTemplate[data['file']['name']]['url'] = response.download;

      }

    };

    this.upload.onBuildItemForm = (item, form) => {

      let name = data['file']['name'];
      form.append("data", data['file']['rawFile']);
      form.append("desc", JSON.stringify(this.fileMap[name]));


    };
  }


  uploadData(){
  // For uploading Data
   this.upload.uploadAll();
}

this.DataTemplate [data ['file'] ['name']] 它包含以下对象

{
  "product": "laptop",
  "info": {
    "mimetype": "image/jpeg",
    "file_id": "dfldpf9c",
    "author": "unknown"
  },
  "Sr_id": "dfldpf9c"

}

这是我的问题,**我如何将“ Sr_id”作为参数发送给邮寄请求** 像下面一样

 this.upload= new FileUploader({ url: this.service.dataUpload('/uploadFile/{**Sr_id**}'), queueLimit: 999, method: 'POST' });
        this.upload.onBeforeUploadItem = (item) => {
          debugger;
          item.withCredentials = false;
        };

0 个答案:

没有答案