One of the features on my website allows users to upload images using a FileReader. Here's the code snippet that handles the file reading:
$("input[type='file']").change(function(e) {
var buttonClicked = $(this);
for (var i = 0; i < e.originalEvent.srcElement.files.length; i++) {
var file = e.originalEvent.srcElement.files[i];
var img = document.createElement("img");
var reader = new FileReader();
reader.onloadend = function() {
img.src = reader.result;
console.log(reader.result);
}
reader.readAsDataURL(file);
}
});
Everything was running smoothly until I attempted to print out the result. When I tried it with a sample image from this link, https://i.sstatic.net/7svQa.jpg, the console logged over 95000 characters.
The size of this particular image is similar to the ones that will be uploaded by users. My plan was to store these images in a database but I'm concerned about how to handle such lengthy image paths. Is there a way to shorten them or obtain the image path differently?
I'm also curious as to why the image URLs are excessively long. Any tips on efficiently storing images (considering hundreds per user and over 500 users) would be greatly appreciated!
Thank you-