get url from file javascript code example
Example 1: create file object from url typescript
fetch('//my-image-url')
.then((e) => {
return e.blob()
})
.then((blob) => {
let b: any = blob
b.lastModifiedDate = new Date()
b.name = ''
return b as File
})
Example 2: javascript read file from url
function getText(){
var request = new XMLHttpRequest();
request.open('GET', 'http://www.xxxxx.com/pocket.txt', true);
request.send(null);
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
var type = request.getResponseHeader('Content-Type');
if (type.indexOf("text") !== 1) {
return request.responseText;
}
}
}
}