Image base64 for arrayBuffer for file

I’m trying to pass base64 image to file, but it always returns empty image. Where am I going wrong?

Hi somdobaixo,

could you please provide a minimal reproduction that we could then run by ourselves? Seeing things first-hand would be far more effective than trying to guess why something is or isn’t working.

Here’s the example.

The image gets empty, I tried using ImageTools.getImageFromBase64 but it did not work inside a forEach. In this example, the path is generated, but the image is empty.

var Observable = require('FuseJS/Observable');
var Base64 = require("FuseJS/Base64");
var FileSystem = require("FuseJS/FileSystem"); 
var list = Observable();

function randomString(length) {
    var result = '';
    var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}

function sistemImage(base64,callback) {  
	var rndName = randomString(6) + ".jpeg";

	var buffer = new ArrayBuffer();
	buffer = Base64.decodeBuffer(base64);
	var fullImagePath = FileSystem.cacheDirectory + "/" + rndName;

	FileSystem.writeBufferToFile(fullImagePath, buffer) 
	     .then(function() {
	          	callback(fullImagePath);
	              console.log("Successful write:" + fullImagePath);
	          }, function(error) {
	              console.log(error);
	});
}

fetch("https://hnd.myhoost.com/api/photos",{ 
	method:"GET"  
}).then(function(result){
	result.json().then(function(json){

		json.forEach(function(item){
			sistemImage(item.uri,function(fullImagePath){
				list.add(fullImagePath);
			});
		});
	});
}).then(function(res){})  
.catch(function(error){});

module.exports={
	list:list
}
<Page ux:Class="Teste">
	<Router ux:Dependency="router"/>

	<JavaScript File="teste.js"/> 

	<ScrollView>
		<StackPanel>
			<Each Items="{list}">
				<Image File="{}" Width="100%" Height="200"/>
			</Each>
		</StackPanel>
	</ScrollView>
</Page>

Tests show that the code provided runs just fine on Fuse 0.38.0 build 13386, so it’s likely a defect in an older Fuse version. Please update and let us know if that helps it.

Thanks, the problem was with the version, after upgrading, everything worked perfectly.

This example worked only in local view, did not work on the device nor on the Nox Android emulator. See details:

Device Android:
Version: 4.4.4
Device: Sansung SM-G530H

Emulate Android:
Version: 4.4.2
Device: AOSP on Shamu