I wonder if there is a solution to open only one file directly without using showOpenFilePicker() function?
I don't want to let other users to pick a different file but API would use only the correct one. I have a root and name of file.
FROM:
this.getFileAsText = async function () {
var [fileHandle] = await window.showOpenFilePicker();
var fileData = await fileHandle.getFile();
return text = await fileData.text();
}
TO:
this.getFileAsText = async function () {
var [fileHandle] = await directFile(myPath/test.txt);
var fileData = await fileHandle.getFile();
return text = await fileData.text();
}
thanks
I tried looking for a solution in the File System Access API, but I could not find one. However, you may not want to use the File System Access API. If the file you are trying to open is a local resource for your app, you can use
The fetch method returns a promise the resolves to a Response object, whose text method will return a promise that resolves to the data in your file as a string. You can manipulate it however you choose at that point. See this documentation at MDN web docs: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API