Using HTML5/Javascript to generate and save a file -


i've been fiddling webgl lately, , have gotten collada reader working. problem it's pretty slow (collada verbose format), i'm going start converting files easier use format (probably json). thing is, have code parse file in javascript, may use exporter too! problem saving.

now, know can parse file, send result server, , have browser request file server download. in reality server has nothing particular process, why involved? have contents of desired file in memory. there way present user download using pure javascript? (i doubt it, might ask...)

and clear: not trying access filesystem without users knowledge! user provide file (probably via drag , drop), script transform file in memory, , user prompted download result. of should "safe" activities far browser concerned.

[edit]: didn't mention upfront, posters answered "flash" valid enough, part of i'm doing attempt highlight can done pure html5... flash right out in case. (though it's valid answer doing "real" web app.) being case looks i'm out of luck unless want involve server. anyway!

ok, creating data:uri trick me, matthew , dennkster pointing option out! here how it:

1) content string called "content" (e.g. creating there or reading innerhtml of tag of built page).

2) build data uri:

uricontent = "data:application/octet-stream," + encodeuricomponent(content); 

there length limitations depending on browser type etc., e.g. firefox 3.6.12 works until @ least 256k. encoding in base64 instead using encodeuricomponent might make things more efficient, me ok.

3) open new window , "redirect" uri prompts download location of javascript generated page:

newwindow = window.open(uricontent, 'neuesdokument'); 

that's it.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -