Skip to content

Instantly share code, notes, and snippets.

@bradkrane
Created March 16, 2022 19:22
Show Gist options
  • Save bradkrane/6bcf1aa9f1343d1f114ef5b8b39a7410 to your computer and use it in GitHub Desktop.
Save bradkrane/6bcf1aa9f1343d1f114ef5b8b39a7410 to your computer and use it in GitHub Desktop.
Paste Base64 and Save As...
<html>
<body>
<p><h2>Base64 to file</h2></p>
<p>
Get data with: <pre>cat &lt;file&gt; | gzip -c | base64</pre><br/>
Paste below and save to file:
</p>
<p>
<textarea id="content" style="width: 580px; height: 250px;"></textarea>
<br/>
<input type="text" id="filename" value="case-file.gz"/><input type="button" id="btn" value="Download" />
</p>
<script>
function downloadBase64(filename, base64) {
// create 'link' to a 'file' for download
var el = document.createElement('a');
el.setAttribute('href', `data:application/gzip;base64,${encodeURIComponent(base64)}`);
el.setAttribute('download', filename);
document.body.appendChild(el);
el.click();
document.body.removeChild(el);
}
// do dl
document.getElementById("btn").addEventListener("click"
,()=>{ downloadBase64(document.getElementById("filename").value.trim(), document.getElementById("content").value.trim());}
, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment