Currently I’m using cordova-camera-preview to take a picture from the phone in order to send a request to the server. I’m sending a base64 picture to the server in JSON format, but the server cannot read the picture.
I tried the server loading pictures in base64 pictures and reads them correctly, but when trying the application, it does not work.
The code related is:
getInfo(picture): Promise<CarInfo> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
console.log(picture);
let jsonInfo = { 'img': picture };
return this.http.post('http://api-url.com', jsonInfo, options).toPromise()
.then(this.extractData)
.catch(this.handleErrorPromise);
}
Also the picture demonstrating that the base64 string works
So what is the problem?
Did you look at what is sent to the server to see if it is valid?
If your backend is broken - or expects a different format, there is not much we can do…
im sorry… is this the correct way to get base 64 using ionic 3?
printMyImage() {
var image = new Image();
image.onload = function() {
var canvas = document.createElement(‘canvas’);
canvas.height = 100;
canvas.width = 100;
var context = canvas.getContext(‘2d’);
context.drawImage(image, 0, 0);
var imageData = canvas.toDataURL(‘image/jpeg’).replace(/^data:image/(png|jpg|jpeg);base64,/, “”); //remove mimetype
window.DatecsPrinter.printImage(
imageData, //base64
canvas.width,
canvas.height,
1,
function() {
printMyBarcode();
},
function(error) {
alert(JSON.stringify(error));
}
)
};
image.src = ‘img/some_image.jpg’;
}