I have a File object
lastModifiedDate: Thu Jun 09 2016 14:55:25 GMT+0200 (CEST),
var image = new Image();
image.src = URL.createObjectURL(myFile);
File object is sort of an extended version of a
Blob that allows it to hold metadata such as filename, size etc.
createObjectURL() will reference both
Blob the data read through the
blob: protocol will only consist of the binary file data itself as when loading via other protocols. No metadata (such as filename) will be provided via the protocol.
Other examples where filename is not considered could be when an image is loaded via for example a PHP or ASPX page (
/getimage.aspx?id=1). Also here there is no metadata provided and browser would suggest something like "getimage.aspx%3Fid=1" as filename in this case. As expected.
IMG tag itself never assumes any filename even if one is used at source point; it only holds what is given to it via the
src attribute/property as-is, as a connection point to retrieve the needed binary data for decoding.
In this case the source point is
blob:*/* which then will be what
IMG tag references via
src, and is what the browser use when the data is to be saved.
The only way to hold on to a filename from the
File object is to keep track of it so you have access to it when needed for download.
But also this is limited as you can only specify a filename using the
download attribute in an
A tag. And of course, some browsers such as <= IE11 does not support this attribute.
<a href="blob:.." download="filename.jpg"><img ..></a>
In IE10+ there is the proprietary method
msSaveBlob() which can be used instead though:
Besides from these there are no common way to specify a default filename from within the client.