简体   繁体   English

HTML5将画布保存到服务器上的文件

[英]HTML5 save canvas to file on server

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 server. 我需要使用html5画布创建一个组件,给出用户可以在其上绘制的图像,并直接(通过一种保存按钮)在服务器上上传它的自定义版本。

Can i use html canvas for it ? 我可以使用html canvas吗? Any suggestion ? 有什么建议吗?

thx in advance thx提前

You can get the image as data-url like this: 您可以将图像作为data-url获取,如下所示:

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). 然后,您可以将此(非常长的字符串)发送到服务器,并在解码后将其保存到文件中(它在base64中编码)。

EDIT: Remember to submit this via POST , as suggested in the comments. 编辑:请记住通过POST提交,如评论中所示。 GET has some length-limits in various browsers, so its likely to exceed those limits with such a huge amout of data. GET在各种浏览器中都有一些长度限制,因此它可能会超出这些极限数据。

Note that this is currently dead-on-arrival for Android (up to and including 2.3). 请注意,Android目前尚未到货(包括2.3)。 Please star this issue - http://code.google.com/p/android/issues/detail?id=7901 请为此问题加注星标 - http://code.google.com/p/android/issues/detail?id=7901

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM