I'd like to understand at want point in time the content of a file blob is actually read into RAM.
I'll use the following scenario where a user simply selects a local image from his disk. The image is then displayed afterwards.
const [fileHandle] = await showOpenFilePicker(); // (1)
const file = await fileHandle.getFile(); // (2)
const imgUrl = URL.createObjectURL(file) // (3)
document.getElementById("img").src = imgUrl; // (4)
The reason why I'm asking is my concrete usecase here. When doing above steps with a bigger amount of images from a slow network drive, I observed that after the above code finished running, the blob does not seem to be in RAM (the image takes a while to be displayed and it's not immediately visible in the 'sources' tab in chrome developer tools).
Would really like to understand what exactly is going on there - thank you all!
It's not a definitive answer, but I tested it and...
URL.createObjectURL(file)
doesn't load up the image, at least not in chrome
const [fileHandle] = await showOpenFilePicker();
const file = await fileHandle.getFile();
const imgUrl = URL.createObjectURL(file)
document.getElementById("img").src = imgUrl;
net::ERR_FILE_NOT_FOUND
errorWhen I skipped the 3rd point the image loaded as expected
It seems like URL.createObjectURL(file)
saves the path to the file on the hard drive. Or at least it looks like this