通过HTTP发布上传图片

时间:2018-09-29 17:44:16

标签: ionic-framework ionic3

我需要将图像保存在存储库中,即使没有代码也要保存图像。我正在尝试使用AJAX和jQuery,但它不发送图像,并且不显示错误。只返回服务器就可以了。

捕获图像的功能:

TirarAnexo() {
    let cameraOptions = {
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      destinationType: this.camera.DestinationType.FILE_URI,
      quality: 100,
      targetWidth: 1000,
      targetHeight: 1000,
      encodingType: this.camera.EncodingType.JPEG,
      correctOrientation: true
    }

    this.camera.getPicture(cameraOptions)
      .then(file_uri =>
        this.img = file_uri,
        err => console.log(err));
  }

发送附件的功能不起作用:

var _data = new FormData();
            var files = this.img;

            if (files.length > 0) {
              _data.append("fileAnexo", files[0]);
              _data.append("contemArq", "S");
            } else {
              _data.append("contemArq", "N");
            }

            _data.append("id", $("#lblIDDespesaAnexo").text());
            $("#boxLoadAnexo").show();

            let h = new Headers();
            h.append('Content-Type', 'application/json; charset=UTF-8');
            h.append('Authorization', 'bearer ' + this.global.tokenGlobal);
            let op = new RequestOptions({ headers: h });

            var ajaxRequest = $.ajax({
              type: "POST",
              url: 'http://xx.xx.xx.xx:xxxx/api/v1/cadastros/despesa/anexo',
              headers: op,
              contentType: false,
              processData: false,
              data: _data
            });
            ajaxRequest.done(function (xhr, textStatus) {
              this.retornoAnexo(xhr + " /// " + textStatus);
            });

0 个答案:

没有答案