Problem:
I’m quite new user of Active Presenter, and I would like to know if it’s possible to read a text file, either in .ini or .xml or .json formatting, with ActivePresenter.
Regards,
ActivePresenter version:
9.0.6
OS:
Windows10
Notes:
Problem:
I’m quite new user of Active Presenter, and I would like to know if it’s possible to read a text file, either in .ini or .xml or .json formatting, with ActivePresenter.
Regards,
ActivePresenter version:
9.0.6
OS:
Windows10
Notes:
Hi,
Are you referring to HTML5 output?
If so, do you want ActivePresenter to read text files from the server side or the client side (HTML5 viewer device)?
Regards,
Hi,
In HTML5 output, Yes.
Regards
Thank you for your response and please also provide the information for the second question so we can assist you better: Where is your file? on a web server or on a viewer computer?
Regards,
Sorry l forgot : it’s on server side. Regards
Hi @pbouille,
You can use Fetch API to load a text file hosted on a server provided that the file is accessible from the HTML5 page (same origin or CORS enabled).
async function fetchTextFile(url) {
try {
const response = await fetch(url);
const text = await response.text();
// or const json = await response.json(); for json text file
} catch (error) {
console.error(error);
}
}
fetchTextFile('your/file/url');
Regards
Thnks @ToanLS , does this mean that Fetch API is usable in active presenter projects (exported in HTML5) ?
Regards
Yes, you can virtually use any client-side JavaScript feature with HTML5 output of ActivePresenter, not just the Fetch API.
Regards
Thanks for this message, but it doesn’t work for me. It seems that the file is read, but text remains empty. My file contains one sentence in text mode.
Any idea ?
Regards
You can press F12 to open the browser developer tools, then switch to Console tab to see if there’s any error messages there.
Regards
Thank you very much for this solution : now I can read the file, that was not in the good directory.
You have been very helpful.
Regards.
Philippe
Hi @ToanLS . Back to this topic…I have a huge problem because fetch seems to be unavailable with export HTML. Do you confirm ? How can we proceed to use project on a desktop standalone (without network nor http or scorm server) ? That’s the purpose for my html5 export. Thanks in advance.
Regards
Hi @pbouille,
fetch
can run in a local HTML file to request a remote file, provided that the remote file is configured to be accessible from the local. If you own the remote server, you can read CORS tutorial I mentioned above to configure that.
In case you want to read a local file, you’ll need to use FileReader because fetch
doesn’t support it.
Regards
Hello. I don’t understand how to read with FileReader the ini file from “Server’s” File System with an exported HTML5 project…
It seems that the reader gives an empty string.
Could you give me an example please ?
Thanks.
Regards,
Philippe
Hello,
In JavaScript, FileReader is used for reading user’s local file systems. For reading remote file (Serve’s files) you should use Fetch API, which was mentioned earlier.
Could you please provide more details about what you are trying to do? This will help us understand your requirements better and provide more accurate assistance.
Regards,
Hello @namnt . In fact I previously tryed without success with fetch. My goal is to have an exported project in HTML5 running alone with initial reading of a configuration json file.
With @ToanLS help I succeeded in AP’s Preview mode, but when exporting fetch aborts because of CORS. That’s why he suggested FileReader to me, but it doesn’t work neither.
My project should work by double-clicking on html exported file.
So I think I don’t really have a server, by the html client can’t read on client’s (that is the same as executong html page…) system file at the moment.
Thank you.
Regards
Hi @pbouille,
I’ve answered to all of your questions via email. Kindly check it out.
Best regards,
Hang