I Want to generate a link for my local woff file. With help of createobjectURL function, A link is created, however, the penalty is in the way of a blob. The URL lifetime is tied to the document in the window on which it was created. The URL runs only on my browser, and when I close relevant tab, the file disappears. So, I'm trying to find a way using js function which creates a perm link to uploaded local file. Currently I used .
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>URL.createObjectURL example</title>
</head>
<body>
<input type="file">
<file>
<p class="p">The URL of file is : </p>
</body>
<script>
var Element = document.querySelector('input');
var file = document.querySelector('file');
Element.addEventListener('change', function() {
var url = URL.createObjectURL(Element.files[0]);
file.src = url;
console.log(url);
var d=document.querySelector(".p");
d.textContent+=url;
});
</script>
</html>
blob:https://www.example.com/123 however I require https://www.example.com/123. I also tried Base 64 encoding. It works but the file size, and speed becomes a drawback even when it is compressed.You're asking for one thing but giving an example of another here.
I Want to generate a permanent link for my local woff file.
You can't generate a URL to file://etc/etc since:
Access to local files is heavily restricted.
I require
https://www.example.com/123
If you want the file to be available on your website: actually upload it to the website! Right now, the file only exists on the user's disk and in the memory being accessed by their browser.
You have to send the data to a server (e.g. with an Ajax POST request) where you have a webservice which reads the request, extracts the file from it, stores the file somewhere, gives it a URL, and then sends the URL back to the browser.