-1

I have an problem with sending binary data from ionic app. The app capture an photo from camera in base64 format and she must send this in binary data format to API server. I have to sent the image at the azure cognitive service for image recognize.

this is my capture function :

public takeFoto(){

const options: CameraOptions = {
  quality: 100,
  destinationType: this.camera.DestinationType.DATA_URL,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  correctOrientation:true,
  saveToPhotoAlbum: true
}

this.camera.getPicture(options).then((imageData) => {

 this.myPhoto = 'data:image/jpeg;base64,' + imageData;
 this.imgData = imageData;

}, (err) => {
 // Handle error

});



}

and this is my post function :

    classifica(){


this.crudService.postAzureApi( /*binary data*/ '','https://northeurope.api.cognitive.microsoft.com/vision/v2.0/tag').then((result)=>{

        console.log(result);
        this.resultPost = result;

},(err)=> {

                        console.log(err);
                     this.resultPost = err;

});

}

the header are : content-type : application/octet-stream and apikey

  • check this answer https://stackoverflow.com/questions/21227078/convert-base64-to-image-in-javascript-jquery – danielarend Jan 22 '19 at 16:27
  • Possible duplicate of [Creating a Blob from a base64 string in JavaScript](https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript) – Endless Jan 22 '19 at 16:45

1 Answers1

0

You can convert to an array of Bytes. There are tools to do so. For example bin2c.

Michael Haephrati
  • 3,660
  • 1
  • 33
  • 56
  • 1
    Thanks but i have solved the problem through this post https://stackoverflow.com/questions/47462008/getting-status-code400-bad-request-when-calling-microsoft-azure-emotion-api-w – user10951166 Jan 22 '19 at 23:11