Can't Get from Nativescript Camera Plugin to byte array


I’m trying to figure out how to let the user take a picture with a camera, and then take that captured picture and upload it to a service. The service requires a byte array, but for the life of me, I can’t figure out any code to get from an imageAsset to a byte array. I’ve tried converting it to an image source, but still can’t find a path to a byte array. I’ve tried saving it locally, but that always fails silently. I m having the camera save it to the camera roll, and I see that it is being created successfully.

Any ideas to go from imageasset to byte array?


hi, normally I have to convert my images to base64, but I see some documentation here in the ImageSource module about ‘loadFromData’ - "the native data (byte array) to load the image from. So you can convert from byte arrays to an image source ( but I don’t see the opposite. @pete.k any guidance here?


Hi, if you want to send pictures you should try this plugin:

For byte array, have you try this?

     var file = new"full path to file");
     var size = file.length();
     var bytes = new byte[size];
     try {
          var buf = new;
, 0, bytes.length);
          //do something
     } catch (ex) {


Thank you for the suggestion, but part of what I am struggling with is getting the path information from the {N} camera module.


do you want the full path? something like this?

var flgEnter=false;
btnFoto.on(buttonModule.Button.tapEvent, function (args) {
        .then(function (imageAsset) {
            console.log("Result is an image asset instance");
            if(imageAsset && && flgEnter){
                console.log("full path:";
        }).catch(function (err) {
            console.log("Error -> " + err.message);


When I do that, I get:
fullpath = <PHAsset: 0x1031cb830> DE8881C3-5ED6-441E-AE9E-6E9A46C0FACE/L0/001 mediaType=1/0, sourceType=1, (2448x3264), creationDate=2017-11-17 18:30:50 +0000, location=0, hidden=0, favorite=0

Still doesn’t seem to give me path info.


Hi, change the code:

console.log("full path:";


console.log("full path:";

It’ll display all the data in json format and you’ll see the path property.


I’m on ios, and when I use console.dir it just outputs {object Object]


are you running on iOS?


Yes. I am running on iOS.


I, I don’t have a license to run in a real iOS device, the emulator doesn’t have the option to take photos. But in theory imageAsset.ios should return the path.


I determine paths using a path service in my Angular app:

import {Injectable, Inject, NgZone} from '@angular/core';
import * as fs from 'file-system';

export class FilesService {
    private ngZone: NgZone,
  ) { }

  public getFilename(path: string) {
    let parts = path.split('/');
    return parts[parts.length - 1];

  public documentsPath(filename: string) {
    return `${fs.knownFolders.documents().path}/${filename}`;



But this presumes you have a path string to begin with doesn’t it? I’m not able to get the path string.


If you don’t mind digging through my codebase…I take images and save them to Firebase in Giftler ( - in the example I mentioned above, I’m simply taking a picture, converting to base64 string, and sending to a REST API service, not saving to device