sS hjs_fileUploadBase64Encoder() { ret hscript([[ var fileConverted = false; function submitWithFileConversion(form) { if (fileConverted) return true; fileConverted = true; var file = $('#fileUploader')[0].files[0]; if (file == null) return true; var reader = new FileReader(); // delay form submit until reader is done reader.onloadend = function () { var b64 = reader.result.replace(/^data:.+;base64,/, ''); $("#f_file_base64").val(b64); console.log("Got base64 data: " + b64.length); setTimeout(function() { $(form).submit(); }, 1000); }; reader.readAsDataURL(file); return false; } ]]); }