I'm trying to preview a file I'm gonna upload to my project. My issue is that whenever I click on the link of the file it opens a new tab on my browser (Chrome) but gets closed immediately after. It works when the link is from a webpage, but I'm using a temp URL. I can preview my file if I copy the temp URL and paste it manually on a new tab, but I want to do it without having to copy the link and paste it. Here's my function:
function Preview() {
var tmppath = URL.createObjectURL(event.target.files[0]) //URL of my file
$("#myDiv").append('<a href="'+tmppath+'" target="_blank">PREVIEW</a>')
};
Here's an example of the generated URL:
blob:http://127.0.0.1:8000/8c17e770-18c1-4713-a601-1d634b0c649f
I appreciate any kind of help. Thank you.