-1

In my contact form7, I upload an image. I need to preview this image before submit. Can you help me? Best regards

showdev
  • 28,454
  • 37
  • 55
  • 73
  • Does this answer your question? [Previewing Image on Contact Form 7](https://stackoverflow.com/questions/66275673/previewing-image-on-contact-form-7) Also see: [CF7 file upload image](https://stackoverflow.com/questions/48857451/cf7-file-upload-image) – showdev Jul 23 '21 at 20:15

1 Answers1

0

Thanks to Erik, I found the solution. In case other users have the same issue, I share here the code:

[file fileuploader filetypes:jpg id:uploader]
<img id="preview" src="#" />
<script>
var uploader = document.getElementById('uploader');
uploader.addEventListener('change', (event) => {
  var binaryData = [];
  binaryData.push(document.getElementById('uploader').files);
  if (binaryData) preview.src = window.URL.createObjectURL(binaryData[0][0]);
});
</script>