文件未在服务器ionic3中上传

Ale*_*lex 10 jira-rest-api ionic-framework ionic-view ionic-native ionic3

我有一个场景,我使用离子将我的本地驱动器(键入jpeg或png)上的图像文件上传到API端点.这是我的代码如下:

fileupload.html - >

//---------------------------------------------------
  <ion-item>
    <ion-input type="file" accept="image/*" (change)="changeListener($event)"> </ion-input>
  </ion-item>
Run Code Online (Sandbox Code Playgroud)

fileupload.ts - >

changeListener($event):void{
    this.file=$event.target.files[0];
    console.log(this.file);
    console.log("upload...");
    let regData={"file":this.file};
    console.log("REGDATAA"+JSON.stringify(regData));
    this.jira.postAttachment("PM-3",regData).subscribe(dataa=>{
      console.log(dataa);
    });
  }
Run Code Online (Sandbox Code Playgroud)

provider.ts - >

public postAttachment(key,data):Observable<any>{
    console.log(JSON.stringify(data))
    return this.http.post(this.api+'/issue/'+key+'/attachments',JSON.stringify(data),{
      headers: new HttpHeaders()
        .append('Authorization', `Basic ${this.auth.getAuthString()}`)
        .append('Content-Type','multipart/form-data';boundary="-------xe3rtyhrfds")
        .append("X-Atlassian-Token", "no-check")
        .append("User-Agent", "xx")
    });
  } 
Run Code Online (Sandbox Code Playgroud)

每次我发送文件时它都没有采用路径并发送一个空响应,这是下面的错误.

 //----------------------------------------------------
  [object File]: {lastModifiedDate: [date] Fri Sep 21 2018 17:42:46 GMT+0530 (India Standard Time), name: "download.jpg", size: 5056, type: "image/jpeg", webkitRelativePath: ""}

 upload...
ion-dev.js (157,11)

 REGDATAA{"file":{}}
ion-dev.js (157,11)

 {"file":{}}
ion-dev.js (157,11)

ERROR [object Object]
Run Code Online (Sandbox Code Playgroud)

我已经解决了CORS问题,同样没有问题.

当我使用邮递员发送相同的响应时,它在这里成功就是我在Postman中发送的内容.

Form-data 
key - "file" (type file) value - "/path/to/my/file"

Headers
Content-type - application/json
x-attlassian token - no-check
Run Code Online (Sandbox Code Playgroud)

有人可以建议这里出了什么问题.

Sud*_*nda 4

使用FormData上传文件.

fileupload.ts

    changeListener(event) {

      const fd = new FormData();
      this.file = event.target.files[0];
      fd.append('file', this.file, this.file.name);
      this.jira.postAttachment("PM-3",fd)
        .subscribe(data => {

          console.log(data);
    });
  }
Run Code Online (Sandbox Code Playgroud)

provider.ts

  postAttachment(key, fd): Observable<any> {

  const httpOptions = {
    headers: new HttpHeaders(
      { 'Content-Type': 'multipart/form-data' },
      { 'Authorization': `Basic ${this.auth.getAuthString()}` })
      };
  return this.http.post(this.api+'/issue/'+key+'/attachments', fd, httpOptions);

  }
Run Code Online (Sandbox Code Playgroud)