I want to create my custom image uploader with HTML and in HTML i need to pass 2 things to Js2bubble : image_name and base64 image String.
I am having problem with this. When i try to use the value of the js2bubble, it is empty. I am using toolbox plugin for js2bubble and here is my html code:
<!-- Include Google Material Icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
/* Hide the default file input button */
#customFileInput {
display: none;
}
/* Style the icon */
#customFileIcon {
background-color: transparent; /* No background color */
color: black; /* Set icon color */
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
}
/* Explicitly set the font size of the icon */
#customFileIcon .material-icons {
font-size: 38px; /* Change this value to adjust icon size */
}
/* Change appearance when hovering over the icon */
#customFileIcon:hover {
color: gray; /* Optional: change color on hover */
}
</style>
<!-- Hidden file input -->
<input type="file" id="customFileInput" accept="image/*" onchange="fileSelected(event)" />
<!-- Custom label acting as a button with an icon -->
<label for="customFileInput" id="customFileIcon">
<span class="material-icons">image</span>
</label>
<script>
function fileSelected(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onloadend = function() {
const base64String = reader.result
.replace("data:", "")
.replace(/^.+,/, "");
const imageName = file.name;
// Combine the base64 string and the image name into a single string
const combinedData = base64String + '|' + imageName;
// Pass the combined data to Bubble using the JavaScript to Bubble plugin
bubble_fn_file(combinedData);
};
reader.readAsDataURL(file); // Read the file as a data URL
}
</script>