rustwebassemblywasm-bindgenyewrust-wasm

Read a file with Rust WASM


I am trying to read a file called Book.txt within my Rust yew app. I am serving Book.txt using trunk's copy-file so that it is accessible from http://localhost:8080/Book.txt. Trying to read the file using std::fs did not work (with error Could not open file: Error { kind: Unsupported, message: "operation not supported on this platform" }), but I'm wondering if there is some other way to read this file. I tried to also use the wasm32-unknown-emscripten target but that didn't seem to do anything. I would really like to avoid if at all possible having a client-server architecture for this where I have the file on the server and read it there as I would like to eventually host this all on github pages.

Help is much appreciated.

Thank you!


Solution