Save JS Binary as File


How can i save binary data in NS ?
i have a bindary content using standard js FIleReader API as below:

        var reader = new FileReader();
        reader.onload = function(e) {
            var result =;

now i am passing this result object from webview to nativescript. Now i want to save this binary content as a file:

            let folder = fs.knownFolders.currentApp().getFolder("videos");
            let file = folder.getFile(name);

                //TODO: need to remove this
                file.writeSync(videoBinary, (error) => {

Now this code works but actually the file is video. When i try to play that video file it sin’t playing…So i am guessing the data i am saying could be wrong.


You are reading the file as string and expect it to stored as video binary, obviously not going to work that way.

May I know why you are using WebView when you can directly read a file, pick a video using intent etc.,


All i needed is media picker. Unfortunelty the existing media picker plugin for NS doesn’t work very well…so have to use this solution…