SolvedNativeScript ImageSourceModule method toBase64String not working (both iOS and Android)

On line 140 of image-source-android.js, quality, base64Stream); I'm getting this error is not a function. I'm using the nativescript-camera to take a picture and then save it to base64 string. Also, the image is saving to my photos even when I set saveToGallery: false.

Here my code:

        width: 1280, height: 720, keepAspectRatio: false, saveToGallery: false
    }).then(function (imageAsset) {
        console.log("Result is an image asset instance");
        viewModel.set("BoardingPassSource", imageAsset);
        var image = ImageSourceModule.fromNativeSource(imageAsset);
        var base64 = image.toBase64String("jpeg");
        // var image = new imageModule.Image();
        // image.imageSource = imageAsset;
        // image.toBase64String("jpeg");
        viewModel.set("base64String", base64);
    }).catch(function (err) {
        console.log("Error -> " + err.message);


  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.****",
    "tns-android": {
      "version": "2.5.0"
  "dependencies": {
    "nativescript-background-http": "^2.4.2",
    "nativescript-barcodescanner": "^2.3.3",
    "nativescript-camera": "0.0.8",
    "nativescript-drawingpad": "^1.1.2",
    "nativescript-drop-down": "^1.5.1",
    "nativescript-loading-indicator": "^2.2.2",
    "nativescript-telerik-ui": "^1.5.1",
    "nativescript-theme-core": "^1.0.2",
    "nativescript-timedatepicker": "^1.1.0",
    "tns-core-modules": "^2.5.0"
  "devDependencies": {
    "babel-traverse": "6.21.0",
    "babel-types": "6.21.0",
    "babylon": "6.14.1",
    "lazy": "1.0.11"
26 Answers

βœ”οΈAccepted Answer

I found another alternative!

        width: 1280, height: 720, keepAspectRatio: false, saveToGallery: false
    }).then(function (imageAsset) {
        imageAsset.getImageAsync(function (res){
            viewModel.set("BoardingPassSource", imageSource); 
            var image = ImageSourceModule.fromNativeSource(imageSource);
            viewModel.set("base64String", image.toBase64String('png'));
            // var stream;
            // var comp ="png", 70, stream);
            console.log("image selected"); 
    }).catch(function (err) {
        console.log("Error -> " + err.message);

now I want to find a way to compress the ImageAsset or the ImageSource.
Any suggestions? @pap5508 @NickIliev

Other Answers:

I used the nativescript-camera and nativescript-imagepicker to take a picture, save it and convert it to base 64. I hope it helps. If anyone has another workaround please let me know.

    // nativescript-camera
        width: 1280, height: 720, keepAspectRatio: false, saveToGallery: true
    }).then(function (imageAsset) {
        console.log("Result is an image asset instance");
        var context = imagepicker.create({
            mode: "single"
        .then(function() {
            return context.present();
        .then(function(selection) {
            console.log("Selection done:");
            selection.forEach(function(selected) {
                selected.getImage().then(res =>{
                    var d = new Date();
                    _photoDateTime = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+
                    viewModel.set("PhotoDateTime", _photoDateTime);

                    viewModel.set("BoardingPassSource", res); 
                    viewModel.set("base64String", res.toBase64String("png"));
                    console.log("image selected");                    
        }).catch(function (e) {
    }).catch(function (err) {
        console.log("Error -> " + err.message);

Related Issues:

NativeScript Error: Cannot find module 'webpack/lib/rules/DescriptionDataMatcherRulePlugin'
@pjmagtubo i had this this morning Upgrading vue-loader fixed it I started getting this error after ...
NativeScript remove button shadow in android api > 21
use below code to remove shadow and still keep ripple effect. Dear friend we ...
NativeScript Rendering NativeScript templates on the web (nothing to do with WebView)
@jeffwhelpley I'm going to initially tackle this with the the (first) option 2 as you suggest Agreed...
NativeScript [iOS] remove ActionBar Border (feature-request)
<ActionBar flat=true> implements this (see #3900) It was merged last month into tns-core-modules I'm...
NativeScript No .ipa found in /Users/.../platforms/ios/build/Debug-iphoneos directory
Adding my 2 cents With @NathanWalker's PR to fix nativescript-localize applied Describe the bug Afte...
NativeScript Navigation is slow on Android with tns-core-modules version 2.3.0
Already in master branch with changes in Image module OOM Exception should be rare if at all ...
NativeScript Memory Leak on iOS since tns-ios 3.0.0
@ivanbuhov Tears of joy in my eyes - this seems to fix it indeed! My test app (linked from the first...
NativeScript Play Services now using AndroidX
We have made some progress just recently Nativescript: 5.4.2 Android: 5.4.0 Clean builds starting to...
NativeScript Build error : building for iOS Simulator, but linking in dylib built for iOS
This seems to work for us for now: We added this to the end of our App_Resources/iOS/build.xcconfig ...
NativeScript {N} 7.0.1 adds the wrong iOS 14 frameworks to project
We have pushed a new RC1 -- this should solve the upload to Apple issue Environment CLI: 7.0.1 iOS R...
NativeScript Android app crashes on launch after upgrading to NativeScript 6.2
Hi All; ok thanks to @brysem he narrowed down the actual library causing the issues After a lot of t...
NativeScript Keyboard overlays views on iOS
Ohh and for the solution above created by @Daxito then I ended up creating a observer for the height...
NativeScript ImageSourceModule method toBase64String not working (both iOS and Android)
I found another alternative! now I want to find a way to compress the ImageAsset or the ImageSource ...
NativeScript Monorepo support
Hey @NickIliev thanks for the response Do you have any clue how should I configure nativescript to b...
NativeScript Nativescript 7 TimePicker/DatePicker error (iOS)
As noted by @lochstar in NS Slack CLI: 7.0.7 Cross-platform modules: 7.0.0 Android Runtime: iOS Runt...
react native keychain SDK Build Tools revision (23.0.1) is too low for project :react-native-keychain.
Ok I found a solution to this For people facing the same problem in the future Hey there ...
material components android Manifest merger failed : Attribute application@appComponentFactory
I had similar problem We're transitioning from github issues to a public buganizer component Rather ...
expo Error: fsevents unavailable (this watcher can only be used on Darwin)
Possible solution: I had installed watchman via npm install -g watchman but apparently this installs...
flutter Multiple commands produce '/build/ios/Debug-iphonesimulator/
I was able to fix it by opening the Runner workspace project in Xcode 10 Then navigate to File ...
flutter App Store iOS submission fails: The bundle does not support the minimum OS Version specified in the Info.plist
After doing a flutter clean changing MinimumOSVersion (inside /ios/Flutter/AppframeworkInfo.plist) t...
flutter '' has different version for the compile (26.1.0) and runtime (27.0.1) classpath
is like this i receive an error when i run flutter run My file is: flutter doctor: ...
flutter Why does my text not wrap?
You have to wrap Column in a flexible Without flexible the column's width is not constrained to the ...
flutter Unexpected top padding in ListView put inside scaffold with no appBar
Yeah this is intentional If you put a widget before the ListView you should wrap the ListView with a...
flutter Missing xcode dependency: Python module "six"
try python2.x -m pip install six by @humblerookie's suggest or brew reinstall python@2 pip install s...
expo exp build:android fails
This works exp start Cancel ctrl c then do exp build:android. Running exp build:android errors fails...
flutter flutter messaging: set the notification icon
Hey guys I fought with this for the better part of a day For some strange reason there are no tutori...
flutter Issue with cloud_firestore - Cannot fit requested classes in a single dex file.
As a workaround you can try enabling mutlidex for Android App by following Enable multidex for apps ...
flutter D8: Program type already present: io.flutter.BuildConfig
@smrucv I received the same error but after flutter clean and flutter packages get everything works ...
flutter Introduction of characters package causes crash on flutter run for preexisting Flutter applications
In my case I resolved the issue with flutter clean After e0ed12c I get this error when building: @ju...
nativescript cli TNS doctor doesn't recognize Xcode (High Sierra)
HI @philipfeldmann Can yhou please run xcodebuild -version and paste the output? May be Xcode is ins...
flutter Making Network http error SocketException: Failed host lookup
@hoc081098 Double-check / make sure you have <uses-permission android:name=android.permission.INTERN...
flutter Support inlining Android/iOS views
iOS view embedding support has landed on master This is still just a preview There are multiple open...
flutter βœ— Android license status unknown.
Hi everyone Steps to Reproduce Please tell us what you were doing and what went wrong If you are run...
react native mapbox gl No static method toHumanReadableAscii
here is workaround: build.gradle got the following error on runtime: java.lang.NoSuchMethodError: No...
flutter idevice_id cannot run on catalina
When you're developing on Catalina Steps to Reproduce Run flutter doctor on macOS Catalina I get the...
flutter type 'List<dynamic>' is not a subtype of type 'List<String>'
The problem is your fromMap constructor is reading from a Map<String dynamic> ...
flutter TextField is hidden by keyboard inside of a Modal Bottom Sheet
This may not work for all situations but I have a modalBottomSheet that contains only a TextField ...
retrofit Kotlin & @Body
You can still use Map just suppress its wildcardness with @JvmSuppressWildcards ...
NativeBase Needs to tap twice to fire onPress function when keyboard is open
@bm-software Use keyboardShouldPersistTaps={'handled'} and will works fine. react-native ...
react native firebase πŸ”₯(Android) Program type already present: io.invertase.firebase.BuildConfig
I think I found my ultimate error here In my package.json file I had at some point earlier ...
flutter Dismissing keyboard programatically
This is a better way as it also clears the focus: FocusScope.of(context).requestFocus(new FocusNode(...
flutter How to solve: Android license status unknown and also Android sdkmanager tool not found? Tried everything(as i think)
The answer is here Uncheck Hide Obsolete Packages and you'll see Android SDK Tools (Obsolete) 26.1.1...
flutter MissingPluginException: No implementation found for method
@mravn-google Yeah turned out I had to quit the flutter run process and start it up again Just a ful...
flutter firebase_auth: ^0.8.0+1 crashes on Android
Here i put this in file: android/ and changed targetSdkVersion to 28 and it worked...
react native modal The statusbar turns white when the modal is open (only on certain devices)
statusBarTranslucent property has been added to Modal of RN 0.62 I think this problem has been solve...