Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ Base64 Encoder
==============

Running live here:
http://jpillora.com/base64-encoder/

http://jpillora.com/base64-encoder/
# Screenshots
![index](https://user-images.githubusercontent.com/24679901/31191252-c6f1dba8-a967-11e7-9248-32b5f4c8740e.png)
42 changes: 37 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@
position: absolute;
right: 10;
top: 10;
opacity: 0.5;
opacity: 0.7;
background: #ff3860;
}

.downloadFile {
position: absolute;
right: 35;
top: 10;
opacity: 0.7;
background: #23d260;
}

textarea {
Expand Down Expand Up @@ -71,6 +80,8 @@ <h2>Base64 File Encoder</h2>
<h4>Drop Files here</h4>
<div id="dropper"></div>
<div id="results"></div>


<script>
if (typeof window.FileReader === 'undefined')
alert('File API & FileReader not supported');
Expand Down Expand Up @@ -102,6 +113,17 @@ <h4>Drop Files here</h4>
e.preventDefault();
};

function downloadURI(uri, name) {
// Ref : https://stackoverflow.com/questions/3916191/download-data-url-file
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}

function fileLoaded(filename, dataUri) {

var div = document.createElement("div");
Expand All @@ -116,6 +138,14 @@ <h4>Drop Files here</h4>
};
div.appendChild(remove);

var newtab = document.createElement("button");
newtab.className = 'downloadFile';
newtab.innerHTML = 'DownloadFile';
newtab.onclick = function () {
downloadURI(dataUri, filename)
};
div.appendChild(newtab);

var name = document.createElement("div");
name.innerHTML = filename;
div.appendChild(name);
Expand All @@ -138,14 +168,16 @@ <h4>Drop Files here</h4>
div.appendChild(ta);

results.appendChild(div);

if (localStorage) localStorage.setItem("b64-" + filename, dataUri);
}

if (localStorage)
for (var filename in localStorage)
if (localStorage) {
for (var filename in localStorage) {
if (filename.indexOf("b64-") === 0)
fileLoaded(filename.replace("b64-", ""), localStorage.getItem(filename));
}
}
</script>
</body>

</html>
</html>