Javascript 如何将规则的反应形式转换为多部分形式?

Javascript 如何将规则的反应形式转换为多部分形式?,javascript,angular,typescript,forms,ionic-framework,Javascript,Angular,Typescript,Forms,Ionic Framework,我正在尝试将一块数据(字符串、数字、文件、bool)上传到api。现在文档说它不是json,而是多部分模式。因为api不接受普通形式的图像,所以我需要多部分形式来上传数据,对吗?现在我有一个问题,转换我的正常形式到一个多部分形式。我在网上查了一下,但没有找到这种方法。我已经试过了,但完全失败了:(另外,我需要从本地存储调用我的文件时也有困难(所有这些都是在我的正常形式下工作的。我也不知道如何准确地更改html以适应新的多部分形式) html(设置了一个标准表单=>我可以保留它吗?) <

我正在尝试将一块数据(字符串、数字、文件、bool)上传到api。现在文档说它不是json,而是多部分模式。因为api不接受普通形式的图像,所以我需要多部分形式来上传数据,对吗?现在我有一个问题,转换我的正常形式到一个多部分形式。我在网上查了一下,但没有找到这种方法。我已经试过了,但完全失败了:(另外,我需要从本地存储调用我的文件时也有困难(所有这些都是在我的正常形式下工作的。我也不知道如何准确地更改html以适应新的多部分形式)

html(设置了一个标准表单=>我可以保留它吗?)

  <form [formGroup]="categoryForm">

<ion-item>
         <ion-icon name="images"></ion-icon>
                <ion-checkbox formControlName="lock"></ion-checkbox>
 </ion-item>


    <ion-item>
      <ion-input [disabled]="tagList?.length > 0" formControlName="category"  name="tagValue"></ion-input>
      <ion-button (click)="addVal()" [disabled]="!categoryForm.valid || tagList?.length > 0">

    </ion-button>
    </ion-item>
</form> 
<ion-button (click)="apiSubmit()">POST</ion-button>
</ion-content>
ngOnInit() {

    this.storage.get('image_data').then((imageFile) => {
      console.log(imageFile)
      this.categoryForm.patchValue({
        image: this.storage.get('image_data')
      });

      this.storage.get('when').then((Data) => {
        this.categoryForm.patchValue({
          when: this.storage.get('when')
        });
      });

    });

    this.categoryForm = new FormGroup({

      'lock': new FormControl(true),

      'category': new FormControl('', Validators.compose([
        Validators.maxLength(25),
        Validators.minLength(1),
        Validators.required
      ])),
      image: new FormControl(null),
      when: new FormControl(null),
    });


    const payload = new FormData();
    this.storage.get('image_data').then((imageFile) => {
      console.log(imageFile);
      this.payload.patchValue({
        image: this.storage.get('image_data')
      });
      payload.append('image': image) // stored retrieved file
      payload.append('category': category) // input string
      payload.append('lock': lock) // bool
      payload.append('when': when) // stored retrieved number (same principle as image)
}