Preview image in base64 format using jQuery on change input file
Preview image in base64 format using jQuery on change input file
Through the use of the programming language, we will work together to solve the "Preview image in base64 format using jQuery on change input file" puzzle in this lesson.
You can preview images in Base64 encoded format using jQuery on the change input file.-
Display image in base64 format on change input file
<!-- Preview image in base64 formats --> <input type="file" name="image" id="image"/> <div class="previewWrapper" style="height:200px; width:300px;"> <img id="previewImage" style="height:100%; width:100%;"> </div> <!-- script --> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(document).ready(function(){ $("body").on("change", "#image", function(e){ var file = e.target.files[0]; var mediabase64data; getBase64(file).then( mediabase64data => $('#previewImage').attr('src', mediabase64data) ); }); }) function getBase64(file) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => resolve(reader.result); reader.onerror = error => reject(error); }); } </script>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Jquery
- Preview image in BLOB URL format on choose file in jQuery
- Validate form using jQuery
- How to validate input type file size in jQuery for multiple records
- Ajax done fail ajaxcomplete in not a function
- Get the href link on click anchor in javascript
- Enable click event on appended element using jQuery
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
- How to pass javascript variable to laravel route on ajax call
- (index):128 Uncaught TypeError: MobileNumberVal.test is not a function
- Jquery-3.6.0.min.js CDN link
- Show and hide target element on click button using javascript/jquery
- How to remove Choose File button in jquery
- How to check object is empty or not in jQuery
- Ajax for multiple form
- Execute function after Ajax call is complete
- How to use and purpose of localstorage in javascript
- How to reset form input element on click
- How to create read more in jquery
- How to preview image before uploading in jQuery
- How to check ajax request is completed in jQuery
- Uncaught TypeError: $.ajaxSetup is not a function
- Append method to add text to body not working
- JQuery find text and show as bold in html page
- How to get closest form input value in jQuery
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')