How to submit html5 canvas as part of form post?

前端 未结 1 1108
暗喜
暗喜 2020-12-31 20:53

I\'m looking to stream the image data from a canvas tag to a node.js server. I can handle the server-side code myself, but how can I submit the data from a canvas? I\'m hopi

相关标签:
1条回答
  • You can use FormData to emulate a normal "multipart/form-data" file submit:

    canvas.toBlob( function(blob) {
    
        var formData = new FormData();
    
        formData.append("image_file", blob );
        var xhr = new XMLHttpRequest;
        xhr.open( "POST", "abc.php" );
        xhr.send(formData);
    
    }, "image/png");
    

    The canvas method .toBlob is specified but not implemented, you can use a polyfill such as canvas-to-blob.js

    0 讨论(0)
提交回复
热议问题