HTML5 save canvas to file on server

后端 未结 2 1610
慢半拍i
慢半拍i 2021-02-04 17:38

i need to create a component using html5 canvas that given an image the user can paint on it and directly (via a kind of save button) upload it\'s customized version on the serv

相关标签:
2条回答
  • 2021-02-04 18:00

    You can get the image as data-url like this:

    var dataUrl = document.getElementById('your-canvas').toDataURL();
    

    You could then send this (very long string) to the server and save it to a file after decoding it (it is encoded in base64).

    EDIT: Remember to submit this via POST, as suggested in the comments. GET has some length-limits in various browsers, so its likely to exceed those limits with such a huge amout of data.

    0 讨论(0)
  • 2021-02-04 18:03

    Note that this is currently dead-on-arrival for Android (up to and including 2.3). Please star this issue - http://code.google.com/p/android/issues/detail?id=7901

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