Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49238

Upload Image via HTTP Post

$
0
0

@Sfsgdfgfdgdsffbv wrote:

I need to save an image in the bank, the image even without being the code. I’m trying with AJAX and jQuery but it does not send the image and it does not display an error. Only return the server is OK.

Function that captures the image:

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));
      }

Function that sends attachment does not work:

  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);
                });

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>