首页 > 解决方案 > 上传图片文件而不是base 64

问题描述

我需要上传一张图片到我的服务器上的一个文件夹。所以我需要上传图像文件,它不能在base 64上。我正在尝试使用文件传输但是它返回错误1并且文件路径获取为'不安全:C:\ fakepath'。

上传文件的代码出错:

AnexoUpload() {
    const fileTransfer: FileTransferObject = this.transfer.create();

    let options: FileUploadOptions = {
      fileKey: 'ionicfile',
      fileName: 'ionicfile',
      chunkedMode: false,
      mimeType: "image/jpeg",
      headers: {},
      params: {
        'contemArq': 'S',
        'id': this.IdAnexo,
        'fileAnexo': this.file
        // the rest of your form fields go here, except photo
      }
    };

    fileTransfer.upload(this.img, 'http://localhost:61473/api/v1/cadastros/despesa/anexo', options)
      .then((data) => {
        this.retornoMsg(data);
      }, (err) => {
        this.retornoErro(err);
      });
  }

  fileEvent(e){ // Change of input type file
    this.file = e.target.files[0];
  }

看法:

<input type="file" [(ngModel)]="ImgArq" (change)=fileEvent($event)/>

标签: ionic-frameworkionic3

解决方案


推荐阅读