See if this works for what you need:
var w=1108, h=598;
var uploadCanvas = function (canvas, callback) {
SeuMetodoDeUploadQueNaoseiQuale(canvas)
.then(function(rtn){
if (callback && rtn.status) {
callback(rtn.url_do_path_imagem);
}
});
};
var createImage = function(callback) {
try {
canvas.backgroundColor = 'white';
var myCanvas = canvas.toDataURL({
format: 'jpeg',
quality: 1,
width: w,
height: h
});
//seu método de upload que não sei qual é...
uploadCanvas(myCanvas, callback);
canvas.backgroundColor = null;
//se precisar pegar o json do canvas
var jsonCanvas = JSON.stringify(canvas);
} catch (e) {
//caso esteja em branco o trabalho, cria apenas um canvas vazio
var whiteCanvas = document.createElement('canvas');
var ctx = whiteCanvas.getContext('2d');
whiteCanvas.height = h;
whiteCanvas.width = w;
whiteCanvas.backgroundColor = "black";
ctx.drawImage(whiteCanvas, whiteCanvas.width, whiteCanvas.height);
var canvasBranco = whiteCanvas.toDataURL('image/jpeg');
//seu método de upload que não sei qual é...
uploadCanvas(canvasBranco, callback);
canvas.backgroundColor = null;
//se precisar pegar o json do canvas
var jsonCanvas = JSON.stringify(canvas);
}
};