For reading data out of the file:
* https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
* https://developer.mozilla.org/en-US/docs/Web/API/FileReader

You'll want to use a FileReader to get an ArrayBuffer out of each selected
file. Beware this is an asynchronous operation!

If you're using embind, you should be able to pass that ArrayBuffer
directly into one of your bound C++ functions that accepts a std::string.

If you're manually setting up bindings between C/C++ and JS, you can use
Module._malloc and Module.writeArrayToMemory to transfer data into the heap
and then pass the pointer in:

http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html#writeArrayToMemory

-- brion




On Fri, Apr 29, 2016 at 8:26 AM, Flix <[email protected]> wrote:

> Hi, this is something that I simply can't do due to my (less than) minimal
> knowledge of Javascript.
>
> The idea is that, since emscripten programs can't acess the local file
> system, maybe we can add, through a custom shell (= html file), a button
> (or some kind of drag and drop area) where the user can pass a file of his
> local file system.
>
> Then, that file is read by Javascript and turned into a char array and
> then a method is called from Javascript into C++ that can read it.
>
> Is this approach viable ?
>
> This is the html code I've found so far:
>
> <!DOCTYPE HTML>
>>
> <html>
>>
> <head>
>>
> </head>
>>
> <body>
>>
> <!--multiple is set to allow multiple files to be selected-->
>
> <input id="myfiles" multiple type="file">
>>
> <div id="your-files"></div>
>>
> </body>
>>
> <script>
>>
> var pullfiles=function(){
>>
>     // love the query selector
>>
>     var fileInput = document.querySelector("#myfiles");
>>
>     var files = fileInput.files;
>>
>     // cache files.length
>>
>     var fl=files.length;
>>
>     var i=0;
>>
>
>
> while ( i < fl) {
>
>         // localize file var in the loop
>>
>         var file = files[i];
>>
>         alert(file.name);  // Here we should read the file and pass it to
>> emscripten
>>
>         i++;
>>
>     }
>>
> }
>>
> // set the input element onchange to call pullfiles
>>
> document.querySelector("#myfiles").onchange=pullfiles;
>>
> </script>
>>
> </html>
>>
>
> Can somebody help me to fill the
>  gaps ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to