views:

351

answers:

2

If for example you follow the link:

data:application/octet-stream;base64,SGVsbG8=

The browser will prompt you to download a file consisting of the data held as base64 in the link itself. Is there any way of suggesting a default file-name for the browser to use? If not, is there a javascript solution?

I'm referring to HTML hyperlinks.

+3  A: 

According to RFC 2397, no, there isn't.

Nor does there appear to be any attribute of the <a> element that you can use either.

Alnitak
A: 

I was unsure of what you meant by 'the link' as I don't see one. But if you add this Header to the response:

Content-Disposition: attachment; filename=somefilenameijustcameupwith.doc;

In C# this is done with: Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

postback
that works if you're downloading a separate file from the server. The point of the "data:" URI is that the data is embedded in the link itself, so no further HTTP request occurs. Try pasting his URI in your browser to see what I mean.
Alnitak
Correct - i've edited the question to clarify this
I should say that _only_ works if you're downloading a separate file. It _won't_ work with a data URI, so is not a useful answer.
Alnitak
So indeed, I misunderstood. Like I mentioned, I was unsure. So the other answer is the correct one.
postback