For study reasons I need to use some of these network APIs like fetch or axios but to get a LOCAL file, so WITHOUT using fs module, or WITHOUT importing them.
I tried with both fetch and axios, but they have not implemented this "feature" to get a local file, also because I think it's not so secure/safe.
fetch:
return new Promise((resolve, reject) => {
fetch('file://users.js')
.then(data => {
console.log(data);
resolve(data);
})
.catch(error => {
console.error('Errore durante il recupero del file:', error);
reject(error);
});
});
I get this error:
cause: Error: not implemented... yet...
axios:
return new Promise((resolve, reject) => {
axios.get('file://users.js')
.then(response => {
console.log(response.data);
resolve(response.data);
})
.catch(error => {
console.error('Errore durante il recupero del file:', error);
reject(error);
});
});
I get this error:
generatedMessage: false, code: 'ERR_ASSERTION', actual: 'file:', expected: 'http:', operator: '=='
Is there some other network api that let me to that?
To
fetch()files onfile:protocol in the browser you can create a browser extension, in"host_permissions"setfile:///*, then you can fetchfile:protocol using absolute path.You can also
fetch()file:protocol usingdeno.Other options include WICG File System Access API
showOpenFilePicker()orshowOpenDirectoryPicker()where implemented, and<input type="file">which is implemented in all modern browsers.