Emscripten, browser file dialog?

I’m playing with emscripten to put some oF stuff online. I tried running the ofSystemLoadDialog but it just fails.

I think it’s because that call works only for desktop OS. I’m looking into using the emscripten api directly, but maybe there’s a simpler way? I see a few classes in the ofxEmscripten addon, but I’m not even sure where the emscripten.h file is.

Thanks!

yes this is not implemted yet, it should be pretty straight forward though but meanwhile you can simply call javascript from c++:

https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-from-c-c

I’ve been able to add the input field (file dialog) to the html, no brainer. However, my intention is to load an image via browser, to my ofApp.

I cannot get the image path from the browser, due to some security constraints.

From what I could gather, I need to read the file from JS, load it into memory, and then somehow share this memory with my ofApp.

I’ve already been able to load the image in the JS client side, I’m now trying to bind C++ classes to JS…

So far it isn’t pretty straight forward, maybe I’m complicating things unnecessarily?

everything you put in the data folder ends up in a kind of virtual file system but that’s all you can access as you would normally do on the desktop. otherwise you need to load form a url which should happen automatically or as you say load the file somehow into js memory through a form or something and share that with c++

Ok, I almost got it now. I created a JS object that allows me to check when a file has been loaded via polling. Then I read it encoded to a base64 string.

I’m able to retrieve this string from c++, and I decode it to an ofBuffer.

Now I’m failing to create an ofImage from the ofBuffer, I get the following:

[ error ] ofImage: loadImage(): couldn't load image from ofBuffer, unable to guess image format from memory`

Can I specify the format somehow? Is there any reason for this besides me doing something wrong with the base64 file?

Got it, javasript puts some kind of header in base64 encodings, here’s how to remove it.