How to fetch files inside uihtml in MATLAB web app
4 views (last 30 days)
Show older comments
I'm using the uihtml component inside uifigure to load a html file. This html file want to fetch a .MOD file or .txt file from local storage, location is static/data/xxx.txt.
just like this
<script>
fetch("./static/data/example.txt")
.then(response => response.text)
.then(textString => {
document.getElementById('viewer').innerHTML = textString;
});
</script>
The problem is I got a 404 error, the file not found. Seems there are some ways to fetch the data but I didn't know, because the .js code can be found in the same location static/js/xxx.js. Are there any way to fetch this data?
0 Comments
Answers (1)
Vidip Jain
on 31 Aug 2023
I understand that you are using the “uihtml” component inside “uifigure” to load a html file and the relative paths inside the HTML file, this might not work as expected because the HTML is embedded within a MATLAB application and is not being served directly from a web server. This can cause issues with relative paths when fetching files.
As a work around for this, you can use MATLAB's “web” function to load your HTML file and specify a local server to serve the files needed by your HTML content.
You can place your files within your MATLAB project directory and use the web function to set up a local server that serves your files. This local server can handle relative paths in your HTML file, then update the URLs for fetching files using an absolute path relative to the local server.
Refer to this documentation for more information: https://www.mathworks.com/help/matlab/ref/web.html
0 Comments
See Also
Categories
Find more on MATLAB Web App Server in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!