Languages

Menu
Sites
Language
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
<script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.file.js"/>
<script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.js"/>
<script type="text/javascript" src="https://raw.github.com/Dashboard-X/html5demos/master/penguin-jump_1372138448_demo_package/lib/tlib/tlib.logger.js"/>
JavaScript:
var filename = '';
	var dataURL = document.getElementById("pic").toDataURL("image/png").replace('data:image/png;base64,', '').replace('data:,', '');
	if (dataURL === '') {
		tlib.logger.err("No image source");
	} else {
			filename=document.getElementById('filename').value;
			filename+=".png";
			createFile(dataURL);
	}
	function createFile(content){
		var newFile = new tlib.file({
			filename : filename,
			virtualRoot : "images",
			success : function() {
				newFile.write(content, {
					success : function() {
					},
					error : function() {
						tlib.logger.err("Text not written to the file");
					}
				});
			},
			error : function() {
				tlib.logger.err("File not created");
			}
		});
	}
li xianjing

Thank you very much.