FileWriter API

743 views
Skip to first unread message

Bauglir

unread,
Oct 25, 2010, 11:28:27 PM10/25/10
to Chromium HTML5
Hi,
1/ I know some parts of FileWriter API do already exist in Chromium
(BlobBuilder), but I'm asking about being actually able to save file
to disc. I've been looking for some plans, but could not find any. Is
there any time frame for this? Like 2 weeks, 2 months? Any?

2/ I'd also like to ask about the actual process of selecting the
target file. I've googled some discussions about <input type="saveas" /
> element, window.saveAs method, discussion about dialog blocking,
etc. Is there any conclusion about this?

3/ I've been testing BlobBuilder and I'm vaning problems with
ArrayBuffer, this kind of object should be appendable to blob, but I
cannot make it work:
var b = new ArrayBuffer(8);
var v1 = new Int32Array(2);
v1[0] = 65;
v1[1] = 66;
var bb = new BlobBuilder();
bb.append("Lorem ipsum");
bb.append(v1.buffer);
bb.append(b);
var bl = bb.getBlob();
var reader = new FileReader();
reader.onload = function(event)
{
alert(event.target.result);
};
reader.readAsBinaryString(bl);

displayed message shows: Lorem ipsum[object ArrayBuffer][object
ArrayBuffer]

http://dev.w3.org/2009/dap/file-system/file-writer.html#the-blobbuilder-interface
http://www.w3.org/TR/file-writer-api/#the-blobbuilder-interface

one draft specifies this method, one does not... Am I doing something
wrong or is this just not implemented in Chromium yet? Tested in
Cromium 8.0.558

Eric Uhrhane

unread,
Oct 26, 2010, 11:25:11 AM10/26/10
to Bauglir, Chromium HTML5
On Mon, Oct 25, 2010 at 8:28 PM, Bauglir <Bronisla...@bauglir.com> wrote:
Hi,
1/ I know some parts of FileWriter API do already exist in Chromium
(BlobBuilder), but I'm asking about being actually able to save file
to disc. I've been looking for some plans, but could not find any. Is
there any time frame for this? Like 2 weeks, 2 months? Any?


The FileSystem API is being implemented now.  We don't have quota support in yet, so at the moment you need to be using an extension or app with unlimited storage quota permissions, and you need to be running fairly new code from the nightly build.  This allows saving inside the sandbox, but doesn't have FileSaver support at this time.
 
2/ I'd also like to ask about the actual process of selecting the
target file. I've googled some discussions about <input type="saveas" /
> element, window.saveAs method, discussion about dialog blocking,
etc. Is there any conclusion about this?


It's in the spec, but nobody is implementing it yet.
 
3/ I've been testing BlobBuilder and I'm vaning problems with
ArrayBuffer, this kind of object should be appendable to blob, but I
cannot make it work:
var b = new ArrayBuffer(8);
var v1 = new Int32Array(2);
v1[0] = 65;
v1[1] = 66;
var bb = new BlobBuilder();
bb.append("Lorem ipsum");
bb.append(v1.buffer);
bb.append(b);
var bl = bb.getBlob();
var reader = new FileReader();
reader.onload = function(event)
{
  alert(event.target.result);
};
reader.readAsBinaryString(bl);

displayed message shows: Lorem ipsum[object ArrayBuffer][object
ArrayBuffer]

http://dev.w3.org/2009/dap/file-system/file-writer.html#the-blobbuilder-interface
http://www.w3.org/TR/file-writer-api/#the-blobbuilder-interface

one draft specifies this method, one does not... Am I doing something
wrong or is this just not implemented in Chromium yet? Tested in
Cromium 8.0.558


Both drafts specify the method; I don't see any difference there.  But they did just get updated yesterday; perhaps you had an old version of the dev.w3.org page cached?  However, ArrayBuffer support in WebKit+Chromium is be implemented as we speak; try again in a week or two.
 
--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.


Bauglir

unread,
Oct 26, 2010, 3:42:37 PM10/26/10
to Chromium HTML5


On Oct 26, 5:25 pm, Eric Uhrhane <er...@chromium.org> wrote:
> On Mon, Oct 25, 2010 at 8:28 PM, Bauglir <Bronislav.Klu...@bauglir.com>wrote:
>
> > Hi,
> > 1/ I know some parts of FileWriter API do already exist in Chromium
> > (BlobBuilder), but I'm asking about being actually able to save file
> > to disc. I've been looking for some plans, but could not find any. Is
> > there any time frame for this? Like 2 weeks, 2 months? Any?
>
> The FileSystem API is being implemented now.  We don't have quota support in
> yet, so at the moment you need to be using an extension or app with
> unlimited storage quota permissions, and you need to be running fairly new
> code from the nightly build.  This allows saving inside the sandbox, but
> doesn't have FileSaver support at this time.

So the point being: there is no way to write file to harddisc using
FileWriter API and noone knows when it might be?
Just asking whether to wait for it or come up with my own solution :)

>
> > 2/ I'd also like to ask about the actual process of selecting the
> > target file. I've googled some discussions about <input type="saveas" /
> > > element, window.saveAs method, discussion about dialog blocking,
> > etc. Is there any conclusion about this?
>
> It's in the spec, but nobody is implementing it yet.
>
I've only found window.saveAs in non-normative example in those
specifications, but not in HTML5 draft, saveas input is only mentioned
in some chromium discussion groups. So I don't know which of those
methods are in which specifications :)



Brona

Eric Uhrhane

unread,
Oct 26, 2010, 4:25:19 PM10/26/10
to Bauglir, Chromium HTML5
On Tue, Oct 26, 2010 at 12:42 PM, Bauglir <Bronisla...@bauglir.com> wrote:


On Oct 26, 5:25 pm, Eric Uhrhane <er...@chromium.org> wrote:
> On Mon, Oct 25, 2010 at 8:28 PM, Bauglir <Bronislav.Klu...@bauglir.com>wrote:
>
> > Hi,
> > 1/ I know some parts of FileWriter API do already exist in Chromium
> > (BlobBuilder), but I'm asking about being actually able to save file
> > to disc. I've been looking for some plans, but could not find any. Is
> > there any time frame for this? Like 2 weeks, 2 months? Any?
>
> The FileSystem API is being implemented now.  We don't have quota support in
> yet, so at the moment you need to be using an extension or app with
> unlimited storage quota permissions, and you need to be running fairly new
> code from the nightly build.  This allows saving inside the sandbox, but
> doesn't have FileSaver support at this time.

So the point being: there is no way to write file to harddisc using
FileWriter API and noone knows when it might be?

It depends on what you're trying to do.  If you want to write to the sandbox, that's in Chrome 8 for apps and extensions, and you can try it out in a nightly build now.  If you just want to invoke the download manager and don't care about the filename, you can create a Blob URL with contentType application/octet-stream and direct an iframe to it [also in Chrome 8].  If you want to be able to pop up a save-as dialog box, that's not implemented and no one knows when it will be.

Just asking whether to wait for it or come up with my own solution :)

>
> > 2/ I'd also like to ask about the actual process of selecting the
> > target file. I've googled some discussions about <input type="saveas" /
> > > element, window.saveAs method, discussion about dialog blocking,
> > etc. Is there any conclusion about this?
>
> It's in the spec, but nobody is implementing it yet.
>
I've only found window.saveAs in non-normative example in those
specifications, but not in HTML5 draft, saveas input is only mentioned
in some chromium discussion groups. So I don't know which of those
methods are in which specifications :)

The example's dated.  If you read the normative section of that spec [FileWriter], you'll see that the FileSaver declares a constructor, so you'd just use "new FileSaver(blob_to_save)" if it were implemented.
 
Brona

Bauglir

unread,
Oct 26, 2010, 5:40:17 PM10/26/10
to Chromium HTML5


On Oct 26, 10:25 pm, Eric Uhrhane <er...@chromium.org> wrote:
Thank you,
I've tried the iframe solution, for testing purposes since there is no
much for it anyway.
I do not know how to create a blob URL with content type, so I've used
blob.slice method

I case anyone wonders:
(file is downloaded to default download directory having some GUID as
name)

<!DOCTYPE HTML>
<html lang='cs'>
<head>
<meta charset="utf-8" />
<title>Blob</title>

</head>
<body onload="doLoad();">
<p>
<button id="save">Save</button>
</p>
<iframe id="iframe"></iframe>
<script>
var iframe = document.getElementById('iframe');
document.getElementById('save').onclick = function(event)
{
var bb = new BlobBuilder();
bb.append("Lorem ipsum");
var blob = bb.getBlob();
// following line will just display the text content in the frame
// used to force content type
//blob = blob.slice(0, blob.size, 'text/plain');
iframe.src = window.createBlobURL(blob);
}
</script>
</body>
</html>

Bauglir

unread,
Oct 26, 2010, 5:46:19 PM10/26/10
to Chromium HTML5


On Oct 26, 10:25 pm, Eric Uhrhane <er...@chromium.org> wrote:
Is there file size limitation for this iframe technique? Or can any
website just store gigabytes of any data without my request or
permission?

Eric Uhrhane

unread,
Oct 26, 2010, 5:48:52 PM10/26/10
to Bauglir, Chromium HTML5
The download doesn't happen in secret; the download manager is quite visible, and generally on any browser will give you an opportunity to cancel the action.  There's no limitation on how big a file you can download.

Daniel Kantor

unread,
Nov 1, 2010, 8:09:31 PM11/1/10
to Eric Uhrhane, Bauglir, Chromium HTML5
Eric, 

Do you know what version has the ability to save a file using the FileSystem API getFile? I am trying it on 8.0.552.23 dev and getting a FileError code 10. When I try and run the code inside an extension with unlimitedStorage I cannot create the FileSystem and I get a FileError code 2. 

thanks,
Dan

kinuko

unread,
Nov 1, 2010, 9:39:55 PM11/1/10
to Chromium HTML5
For now FileSystem API does not work in extensions on any chrome 8
revisions.
You'll need to run the code in a hosted Web page, or as a hosted Web
apps with unlimitedStorage permission if you want to create new files
with getFile.
Extensions will be supported in chrome 9 at worst, but it's not in
yet. Sorry for the confusion.

If it's just for testing, -unlimited-quota-for-files flag would be
helpful.
This allows any Web pages (except for extensions, extensions are a bit
special) to use unlimited quota for files.

On Nov 1, 5:09 pm, Daniel Kantor <dan.kan...@gmail.com> wrote:
> Eric,
>
> Do you know what version has the ability to save a file using the FileSystem
> API getFile? I am trying it on 8.0.552.23 dev and getting a FileError code
> 10. When I try and run the code inside an extension with unlimitedStorage I
> cannot create the FileSystem and I get a FileError code 2.
>
> thanks,
> Dan
>
>
>
> On Tue, Oct 26, 2010 at 11:25 AM, Eric Uhrhane <er...@chromium.org> wrote:
> >>http://dev.w3.org/2009/dap/file-system/file-writer.html#the-blobbuild...
> >>http://www.w3.org/TR/file-writer-api/#the-blobbuilder-interface
>
> >> one draft specifies this method, one does not... Am I doing something
> >> wrong or is this just not implemented in Chromium yet? Tested in
> >> Cromium 8.0.558
>
> > Both drafts specify the method; I don't see any difference there.  But they
> > did just get updated yesterday; perhaps you had an old version of the
> > dev.w3.org page cached?  However, ArrayBuffer support in WebKit+Chromium
> > is be implemented as we speak; try again in a week or two.
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
> >> "Chromium HTML5" group.
> >> To post to this group, send email to chromium-ht...@chromium.org.
> >> To unsubscribe from this group, send email to
> >> chromium-html5+unsubscr...@chromium.org<chromium-html5%2Bunsubscr...@chromium.org>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium HTML5" group.
> > To post to this group, send email to chromium-ht...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-html5+unsubscr...@chromium.org<chromium-html5%2Bunsubscr...@chromium.org>
> > .

Daniel Kantor

unread,
Nov 1, 2010, 11:36:33 PM11/1/10
to kinuko, Chromium HTML5
Ok got it. Thanks for clearing it up. 

Dan

To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.

rudiedirkx

unread,
Dec 12, 2010, 6:15:28 PM12/12/10
to Chromium HTML5
I'm using Chrome 9.0.597.16 dev. My window doesn't have a
createBlobURL function. How do I offer a file for download?

To get the dataURL I use:

var bb = new BlobBuilder();
b.append('some text')
var blob = bb.getBlob('text/plain');
var fr = new FileReader();
fr.onload = function(e) {
document.location = this.result; // voila the dataURL
}
fr.readAsDataURL(blob);

This works. The file is opened in the same window. It doesn't download
the file however! If I change the content-type to application/octet-
stream, the dataURL doesn't open.

I want the client to download, not open it as a page.

Thanks

Rudie

rudiedirkx

unread,
Dec 12, 2010, 7:17:58 PM12/12/10
to Chromium HTML5
I've created a tiny test online: http://hotblocks.nl/tests/ajax/filewriter.html

To change the new file's content-type, you can:

useContentType = 'text/html';

with your inspector. text/html and text/plain show fine. application/
pdf opens the PDF viewer (which tells us that's it's not a valid PDF
file which we know). application/force-download and application/octet-
stream won't even show. The console tells us:

Failed to load resource [data url]

Thanks!

PhistucK

unread,
Dec 13, 2010, 2:08:49 AM12/13/10
to rudiedirkx, Chromium HTML5
"createBlobURL" was renamed to "createObjectURL" as of Chrome 9 onwards.

PhistucK



Rudie Dirkx

unread,
Dec 13, 2010, 3:03:04 PM12/13/10
to Chromium HTML5
That doesn't answer the question: how do I offer the plain/text file
for download? open(createObjectURL(file)) just opens the file in a new
window, it doesn't make it download. Thanks/

Rudie Dirkx

Dmitry Titov

unread,
Dec 13, 2010, 5:45:21 PM12/13/10
to Rudie Dirkx, Chromium HTML5, Jian Li, Darin Fisher
Adding folks who probably know this.

Rudie Dirkx

unread,
Dec 19, 2010, 10:52:13 AM12/19/10
to Dmitry Titov, Chromium HTML5, Jian Li, Darin Fisher
Nobody knows this?? How do I force a newly created Blob/File to
download (instead of just show using it using the dataUrl)?

Thanks!


--
Greetlingss,
Rudie Dirkx

Eric Bidelman

unread,
Feb 22, 2011, 5:39:53 PM2/22/11
to Paul Kinlan, Rudie Dirkx, Dmitry Titov, Chromium HTML5, Jian Li, Darin Fisher
Also check out:

which does what Paul mentioned, but doesn't use a library.

Note: you'll need to use the vendor prefixes of createObjectURL (i.e. window.webkitURL.createObjectURL).

Eric

On Tue, Feb 22, 2011 at 2:15 PM, Paul Kinlan <paulk...@chromium.org> wrote:
Hi,


In Chrome you can create an iframe and set the src to be the blob (object) - this will make Chrome initiate a download.



  var bb = new BlobBuilder();          
var output = Builder.output({"binary":true});
  
  var ui8a = new Uint8Array(output.length);
          
  for(var i = 0; i< output.length; i++) {
      ui8a[i] = output.charCodeAt(i);
  }
          
  bb.append(ui8a.buffer);
 
  var blob = bb.getBlob("application/octet-stream");
  var saveas = document.createElement("iframe");
  saveas.style.display = "none";
            
  if(!!window.createObjectURL == false) {
    saveas.src = window.webkitURL.createObjectURL(blob);
  }
  else {
    saveas.src = window.createObjectURL(blob);
  }

Thanks,
P
Paul Kinlan
Developer Advocate @ Google for Chrome and HTML5
t: +447730517944
tw: @Paul_Kinlan
LinkedIn: http://uk.linkedin.com/in/paulkinlan
Blog: http://paul.kinlan.me
Skype: paul.kinlan

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.



--
Eric Bidelman
Developer Relations - Google
e.bid...@google.com

Paul Kinlan

unread,
Feb 22, 2011, 5:15:18 PM2/22/11
to Rudie Dirkx, Dmitry Titov, Chromium HTML5, Jian Li, Darin Fisher
Hi,


In Chrome you can create an iframe and set the src to be the blob (object) - this will make Chrome initiate a download.

  var bb = new BlobBuilder();          
var output = Builder.output({"binary":true});
  
  var ui8a = new Uint8Array(output.length);
          
  for(var i = 0; i< output.length; i++) {
      ui8a[i] = output.charCodeAt(i);
  }
          
  bb.append(ui8a.buffer);
 
  var blob = bb.getBlob("application/octet-stream");
  var saveas = document.createElement("iframe");
  saveas.style.display = "none";
            
  if(!!window.createObjectURL == false) {
    saveas.src = window.webkitURL.createObjectURL(blob);
  }
  else {
    saveas.src = window.createObjectURL(blob);
  }

Thanks,
P
Reply all
Reply to author
Forward
0 new messages