How to fetch files inside uihtml in MATLAB web app
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Vidip Jain
2023 年 8 月 31 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Web App Server についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!