is the base64 module working?

hi i’m wondering if the base64 module is working , if yes , anyone to teach how it works , and if the module can transform an image to base64, i’m trying to find a solution for uploading image without success

thank you

I can take a picture and upload it to Parse. Here’s my code:

function TakeImage(){
    Camera.takePicture().then(
    function(image) {
        imageName = image.name;

        var args = { desiredWidth:200, desiredHeight:200, mode:ImageTools.SCALE_AND_CROP, performInPlace:true };
        ImageTools.resize(image, args).then(
            function(image) {
                CompressImage(image);
            }
        ).catch(
            function(reason) {
                console.log("Couldn't resize image: "+reason);
            }
        );
    }
        ).catch(
        function(reason){
            console.log("Couldn't take picture: "+reason);
        }
    );
}

function CompressImage(file){
    var reader  = new FileReader();
    reader.onloadend = function () {
        base64String = reader.result.split(',')[1];
        UploadImage();
    }

    if(file){
        reader.readAsDataURL(file);
      }
}

function UploadImage(){
    var parseFile = new Parse.File(imageName, { base64: base64String });
    parseFile.save();
}

Hi Cristian,

I wanted to try your example but I have an issue with “ImageTools”, as I know it’s a package, but when I added to my project:

 "Packages": [
    "Fuse",
    "Fuse.Camera",
    "FuseJS",
    "Fuse.ImageTools"
 ],

    var ImageTools = require('FuseJS/ImageTools');

I got this error:

    ...unoproj: E0100: Package 'Fuse.Imagetools' was not found

So, please how can I use it?

Could it be you got the casing wrong in your .unoproj file?

Your pasted list of packages got the correct casing FuseTools", but the error message has a lowercase t inFuse.Imagetools`.

You need to include this in your Js var ImageTools = require("FuseJS/ImageTools");

Karsten sorry it was in lower case because I rewrite in the post, but as you can see here. that is not the problem.

And Cristian in my last post I mentioned I had already include:

    var ImageTools = require('FuseJS/ImageTools');

But the error is for the package in my .unoproj, I don’t know why, can you tell me if you have the last version of Fuse? Because I have, maybe is that the problem…

In what version of Fuse are you working on?

v. 0.20.2 I thought it was the last one, but I just found out they lunched another one 5 days ago. In wich version are you??

In 0.21.6650

@Cristian are there docs for ImageTools?? I’m confused is this something Fuse provides in 0.21? or a third party?

Edwin Reynoso wrote:

@Cristian are there docs for ImageTools?? I’m confused is this something Fuse provides in 0.21? or a third party?

ImageTools is a API that Fuse provides. But I think the docs are not up to date.

Awesome I’ll see if I can play with it thanks

the solution using ImageTools

var picture = Observable()

function takePicture(){
    camera.takePicture(400, 400).then(function(file){
      encodeImage(file)
      console.log("i'm here")
    }).catch(function(reason){
      console.log("loubou" + reason)
    })
}

function encodeImage(image){
  ImageTools.getBase64FromImage(image).then(function(ImageBase){
    picture.value = ImageBase;
    console.log("hey" + " " + JSON.stringify(ImageBase))
  })
}

In the version 0.22 of Fuse not working. Please helpme!!

This is the log:

LOG: InternalError: Script error: Name: Fuse.Scripting.Error Error message: require(): module not found: FuseJS/ImageTools File name: LoginPage.js Line number: 2 Source line: var ImageTools = require(“FuseJS/ImageTools”); JS stack trace: [Uno code] at Fuse.Scripting.ScriptModule+RequireContext.Require (System.String id) [0x00000] in :0 at Fuse.Scripting.ScriptModule+RequireContext.Require (System.Object[] args) [0x00000] in :0 at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in :0 LOG: Error: JavaScript error in LoginPage.js line 2. require(): module not found: FuseJS/ImageTools in Fuse.Reactive.JavaScript LOG: InternalError: Script error: Name: Fuse.Scripting.Error Error message: require(): module not found: FuseJS/ImageTools File name: LoginPage.js Line number: 2 Source line: var ImageTools = require(“FuseJS/ImageTools”); JS stack trace: [Uno code] at Fuse.Scripting.ScriptModule+RequireContext.Require (System.String id) [0x00000] in :0 at Fuse.Scripting.ScriptModule+RequireContext.Require (System.Object[] args) [0x00000] in :0 at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in :0 LOG: Error: JavaScript error in LoginPage.js line 2. require(): module not found: FuseJS/ImageTools in Fuse.Reactive.JavaScript LOG: InternalError: Script error: Name: Fuse.Scripting.Error Error message: require(): module not found: FuseJS/ImageTools File name: LoginPage.js Line number: 2 Source line: var ImageTools = require(‘FuseJS/ImageTools’); JS stack trace: [Uno code] at Fuse.Scripting.ScriptModule+RequireContext.Require (System.String id) [0x00000] in :0 at Fuse.Scripting.ScriptModule+RequireContext.Require (System.Object[] args) [0x00000] in :0 at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in :0 LOG: Error: JavaScript error in LoginPage.js line 2. require(): module not found: FuseJS/ImageTools in Fuse.Reactive.JavaScript LOG: InternalError: Script error: Name: Fuse.Scripting.Error Error message: require(): module not found: FuseJS/ImageTools File name: LoginPage.js Line number: 2 Source line: var ImageTools = require(“FuseJS/ImageTools”); JS stack trace: [Uno code] at Fuse.Scripting.ScriptModule+RequireContext.Require (System.String id) [0x00000] in :0 at Fuse.Scripting.ScriptModule+RequireContext.Require (System.Object[] args) [0x00000] in :0 at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in :0 LOG: Error: JavaScript error in LoginPage.js line 2. require(): module not found: FuseJS/ImageTools in Fuse.Reactive.JavaScript LOG: Ingresa al APP LOG: InternalError: Script error: Name: Fuse.Scripting.Error Error message: require(): module not found: FuseJS/ImageTools File name: LoginPage.js Line number: 3 Source line: var ImageTools = require(“FuseJS/ImageTools”); JS stack trace: [Uno code] at Fuse.Scripting.ScriptModule+RequireContext.Require (System.String id) [0x00000] in :0 at Fuse.Scripting.ScriptModule+RequireContext.Require (System.Object[] args) [0x00000] in :0 at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in :0 LOG: Error: JavaScript error in LoginPage.js line 3. require(): module not found: FuseJS/ImageTools in Fuse.Reactive.JavaScript

it should work after an uno clean

Run the command “uno clean” in the directory of the app and get the same error