Reputation: 1
This may seem pointless but how would I go about coding in JavaScript... I want to upload an image from my pc to my browser and then save it back to my pc in a different location.
Upvotes: 0
Views: 188
Reputation: 1
You can use <input type="file">
element, change
event, URL.createObjectURL()
, <a>
element, download
attribute, .click()
<input type="file" />
<script>
document.querySelector("input[type=file]")
.addEventListener("change", function(e) {
var a = document.createElement("a");
a.href = URL.createObjectURL(e.target.files[0]);
a.download = e.target.files[0].name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
})
</script>
Upvotes: 2