Languages

English

How to save data URL into a normal file in web app?

I got the data URL from canvas, and want to save it into a file, how can I do it in web app?

Thanks.

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

2 Replies
konduri sai swathi
Hi, Include the below libraries in your application
  1. <script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.file.js"/>
  2. <script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.js"/>
  3. <script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.logger.js"/>
JavaScript:
  1. var filename = '';
  2. var dataURL = document.getElementById("pic").toDataURL("image/png").replace('data:image/png;base64,', '').replace('data:,', '');
  3. if (dataURL === '') {
  4. tlib.logger.err("No image source");
  5. } else {
  6. filename=document.getElementById('filename').value;
  7. filename+=".png";
  8. createFile(dataURL);
  9. }
  10. function createFile(content){
  11. var newFile = new tlib.file({
  12. filename : filename,
  13. virtualRoot : "images",
  14. success : function() {
  15. newFile.write(content, {
  16. success : function() {
  17. },
  18. error : function() {
  19. tlib.logger.err("Text not written to the file");
  20. }
  21. });
  22. },
  23. error : function() {
  24. tlib.logger.err("File not created");
  25. }
  26. });
  27. }
li xianjing

Thank you very much.