views:

45

answers:

3

I need to let the user to download a file created on the fly from some data contained in the extension, but I don't want to do this server-side.

As a real-world example : There is a variable containing the text "hello world". I want the user to be able to download/create a .TXT file containing such text.

Is it possible ?

-edited-

Solutions so far:

window.saveAs - not working at all

createObjectURL - works, but the filename and other options can't be customized yet

copy data to clipboard - works, but too many steps are required to the user

create a GoogleDocs document - could work, but needs messing with the API and Oauth

+1  A: 

I don't think this is possible because of safety reasons

Harmen
A: 

In the Chromium-extensions Gogle Group I have found this working example: (I have modified it to work from the pop-up)

BuiltBlob = new BlobBuilder(""); 
BuiltBlob.append("Hello, world"); 
BlobToSave = BuiltBlob.getBlob(); 
chrome.tabs.create({'url': createObjectURL(BlobToSave), 'selected': false});

But the filename is not set, ending with something like cf8a56bf-d724-4b97-b10f-e252961135bd

On the The W3C docs ( http://dev.w3.org/2009/dap/file-system/file-writer.html ) I've found this not working example:

var bb = new BlobBuilder(); 
bb.append("Lorem ipsum"); 
var fileSaver = window.saveAs(bb.getBlob(), "test_file"); 
fileSaver.onwriteend = myOnWriteEnd; 

but window.saveAs doesn't appear to exists.

Googleing around I've found outdated Google Gears references, but nothing else, maybe because I'm dealing with something too new to have proper documentation ?

Is there a way to set the filename/mime-type to the first example?

UVL
Well, HTML5 isn't even finished as a spec yet, let alone ready for full-scale implementation across the web. Unfortunately, HTML5 is 'the next big thing' just a bit too early. It's not surprising file writer doesn't work yet. You can always check HTML5test to see what your browser supports so far.
Xorlev
+1  A: 

I think the only way is to call save dialog through flash, see Downloadify library.

serg
Few hours ago I had no idea how to handle this, and now I have already two ways, thanks!
UVL
I've finally tested Downloadify, and it doesn't work due to the flash security sandbox. From the docs:"**Important! The swf has been compiled for online use only. Testing from the file path (i.e. file:// ) will not work as it will violate the security sandbox.**"I can't use the Blob option too, as it works only in the latest Chrome dev versions, so for now I can't provide any export function to the extension users... :(
UVL