I am very new to JavascriptFFI
and will very much appreciate help here.
I have a working javascript code to grab image as FILE URI
from camera (via cordova camera plugin). Now, it can return either error or file uri on success. We want to map them to Left Int Text
and Right GHCJS.DOM.Types.File
(not sure if I got the type of FILE URI
right).
Here is the javascript code (untested since I modified it off the tested one to return just fileuri or error, instead of displaying it in the browser).
<script type="text/javascript" charset="utf-8">
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
console.log("success");
return imageURI;
}
// A button will call this function for testing
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as binary data
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.FILE_URI });
}
// Called if something bad happens.
//
function onFail(message) {
console.log("failure");
return[1, message];
}
</script>
I will appreciate pointers on how to do the FFI to navigator.camera.getPicture
with ghcjs-dom-0.2.3.1 (I am using it with Reflex) such that returned result is in Either.
I can then wrap the File URI
in ByteString
(I think through Cordova file api to convert it first to arraybuffer
) and send it off to remove server for persistence.