How to upload this to the PHP server using jQuery?
It's quite simple: Convert your canvas to blob
and send an Ajax, with a small modification to the settings.
function ajaxUpload(options) {
options = $.extend({}, {contentType: false, cache: false, processData: false}, options);
return $.ajax(options);
}
canvas.toBlob(function (blob) {
var data = new FormData();
data.append('imagem', blob);
ajaxUpload({url: '/upload.php', data: data}).success(function () {
console.log('upload concluído com sucesso');
});
});
Is it the right way to upload? Will not you bring me damages for not being a normal upload, with form input etc ...?
Well, the only difference I see is that you will always have to use ajax. Furthermore, with input
, usually in upload submission, the filename is sent, other than blob
, which does not have the filename of the source file, but in this case could be solved in a simple way: Placing the third parameter in the .append
call:
data.append('imagem', blob, 'imagem.jpg')
In addition, there are no "problems", but differences.