Skip to content

Instantly share code, notes, and snippets.

@trupakufi
Created February 18, 2022 00:57
Show Gist options
  • Save trupakufi/f2b3015f55990aa3976eeda50f5c8f25 to your computer and use it in GitHub Desktop.
Save trupakufi/f2b3015f55990aa3976eeda50f5c8f25 to your computer and use it in GitHub Desktop.
Uma forma muito simples de fazer um Preview de uma imagem, antes de fazer o upload, utilizando recursos nativos do js, muito bom, e muito prático.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Image Previewer Uploader</title>
</head>
<body>
<div>
<img
src="#"
alt="Preview Image Upload"
width="200"
id="image-previewer"
/>
</div>
<form action="">
<input
type="file"
name="input-image-upload"
onchange="PreviewImage()"
id="image-uploader"
/>
</form>
<script>
const image = document.getElementById("image-previewer");
function PreviewImage() {
image.src = URL.createObjectURL(event.target.files[0]);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment