Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to embed filename in data: url

35 views
Skip to first unread message

biju

unread,
Nov 17, 2007, 9:37:09 AM11/17/07
to
How to embed filename in data: url?
I would like to create a file download with proper filename from
JavaScript without using a server round trip.
I was planning to do it using data: url it gives proper mime-type,
but how can I add filename also in data: url?

TIA
Biju

John J. Barton

unread,
Nov 17, 2007, 12:33:26 PM11/17/07
to
In Firebug I put the filename as a parameter of the media type:
data:text/javascript;fileName=x%2Cy.js;baseLineNumber=10,<the-url-encoded-data>
You can put name/value pairs after the media type and before the comma.
Of course you have to url encode the parameter values.

John.

biju

unread,
Nov 18, 2007, 2:36:55 AM11/18/07
to
On Nov 17, 1:33 pm, "John J. Barton" <johnjbar...@johnjbarton.com>
wrote:

> In Firebug I put the filename as a parameter of the media type:
> data:text/javascript;fileName=x%2Cy.js;baseLineNumber=10,<the-url-encoded-data>

Thanks, I tried, it did not worked for me
I think this feature is not there in Mozilla Firefox

Following is what I tried in Firefox
location='data:application/zip;fileName=x
%2Cy.js;baseLineNumber=10,sometext';
location='data:application/zip;name="myzipfile.zip";Content-
disposition=inline%3Bfilename%3D%22myzipfile.zip%22,sometext';
location='data:application/zip;Content-disposition=inline%3Bfilename%3D
%22myzipfile.zip%22,sometext';
location='data:application/zip;Content-disposition=inline%3Bfilename
%3Dmyzipfile.zip,sometext';
location='data:application/zip;name=myzipfile.zip,sometext';
location='data:application/zip;Content-
disposition=inline;filename=myzipfile.zip,sometext';

nothing gave me "x,y.js" or "myzipfile.zip" as file name while saving

I also tried
location='data:text/javascript;fileName=x
%2Cy.js;baseLineNumber=10,sometext';
and the "File > Save File As" still not getting "x,y.js" as file name

Boris Zbarsky

unread,
Nov 18, 2007, 1:08:41 PM11/18/07
to
biju wrote:
> How to embed filename in data: url?

Please see http://www.google.com/search?q=data+uri+rfc the first hit.

If it doesn't mention filenames, then you can't.

-Boris

John J. Barton

unread,
Nov 18, 2007, 6:58:38 PM11/18/07
to

Well RFC2397 won't mention filenames, but the program interpreting the
mediatype in the 2397 dataurl might support a filename parameter.

Or as biju already discovered, they might not.

John.

Boris Zbarsky

unread,
Nov 18, 2007, 7:14:25 PM11/18/07
to
John J. Barton wrote:
> Well RFC2397 won't mention filenames, but the program interpreting the
> mediatype in the 2397 dataurl might support a filename parameter.

If the mediatype in question defines one, yes. I doubt that many do.

-Boris

biju

unread,
Nov 19, 2007, 9:49:40 PM11/19/07
to
On Nov 18, 2:08 pm, Boris Zbarsky <bzbar...@mit.edu> wrote:
> Please seehttp://www.google.com/search?q=data+uri+rfcthe first hit.

ie, http://www.ietf.org/rfc/rfc2397.txt it dont have letter sequence
"file" or "name"

at https://bugzilla.mozilla.org/show_bug.cgi?id=371432#c6
I saw...
(and we can attach disposition bits like filename just fine within the
spec)
So just wondered if there is a way to avoid a server round trip.

Thanks all for the advice...

0 new messages