Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local file usage #45

Closed
slotthhy opened this issue Aug 26, 2018 · 2 comments
Closed

Local file usage #45

slotthhy opened this issue Aug 26, 2018 · 2 comments

Comments

@slotthhy
Copy link

The program I'm intending to use with CheerpJ uses Swing file choosers for input in the form of XML files and other things. It doesn't appear to me that CheerpJ includes functionality for selecting a file from the user's computer outside of the sandboxed virtual filesystem outlined in the documents. That is, when opening a file chooser within the program, the virtual filesystem is displayed and only files within that can be selected.

How would one go about allowing users to select files from their local machine, such as from their Downloads or Documents folder? Would additional javascript need to be written to allow for this type of interaction with CheerpJ?

@alexp-sssup
Copy link
Member

The best strategy is to write a small amount of JS code to get native access to the browser file selection dialog. The file data can be passed as a Java byte[] to Java code using CheerpJ interop APIs. The general idea would be

// Assuming 'fileBuffer' is an Int8Array created from file data
var javaByteArray = cjTypedArrayToJava(fileBuffer);
cjCall("SomeClass", "parseXMLData", javaByteArray).then(function(ret) { /* Do something with returned data*/ });

Relevant docs:
https://github.com/leaningtech/cheerpj-meta/wiki/Runtime-API#cjcall--cjnew
https://github.com/leaningtech/cheerpj-meta/wiki/Runtime-API#data-conversion

@alexp-sssup
Copy link
Member

This issue is extensively discussed and tracked here #98

Closing this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants