Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2020 17:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Please select a file to upload:
<input id="file" type="file" accept="image/*">
<button id="button">Upload</button>
<script runat="client">
.addEventListener("click", function() {
var files = document.getElementById("file").files;
if (files.length > 0) {
function getBase64(file) {
var reader = new FileReader();
reader.onload = function() {
//prepare data to pass to processing page
var fileEncoded = reader.result;
var base64enc = fileEncoded.split(";base64,")[1];
var fullFileName = document.getElementById("file").files[0].name;
var fileName = fullFileName.split(".")[0];
var assetName = fullFileName.split(".")[1];
fetch("", { //provide URL of the processing page
method: "POST",
headers: {
"Content-Type": "application/json"
body: JSON.stringify({
base64enc: base64enc,
fileName: fileName,
assetName: assetName
.then(function(res) {
.catch(function(err) {
reader.onerror = function(error) {
console.log('Error: ', error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment