Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hello,
I am attempting to encode a byte array (blob) into a base64 string so that I can save it, then send it via Rest call to an external service from thingworks. Below is the current version of my code:
var blob = Things["SystemRepository"].LoadImage({
path: filename /* STRING */
});
var jsonObj = { //an attempt to fix the "no array member found in the JSON object error," to no avail.
"bytes":[]
};
for(var i = 0; i < blob.length; i++)
{
jsonObj["bytes"][i] = blob[i]; //copy the array to the jsonObj array
}
var arr = jsonObj["bytes"];
var basestring = base64EncodeBytes(jsonObj);
The current issue I am having is when I try to convert to base64 string. I am receiving an error " Invalid Argument Type (no array member found in the JSON object" Prior to this, i received an error when passing the array, rather than a JSON object with an array, straight into the function and received the error "Invalid Argument Type (not a JSON object)". Prior to that, I had passed the result from the LoadBytes function straight into the function, and received the same error "not a json object."
The filename given to the LoadBytes service is valid.
I feel that I am close, yet I can not figure out how to get the image to base64 string. Any help is appreciated, thanks!
Solved! Go to Solution.
Hello,
Indeed, you were very close -- needed just to change "bytes" to "array" :)
Here's the short working version:
var blobArray = []; for (var i = 0; i < blob.length; i++) blobArray.push(blob[i]); var result = base64EncodeBytes({ array: blobArray });
Regards,
Constantine
Hello,
Indeed, you were very close -- needed just to change "bytes" to "array" :)
Here's the short working version:
var blobArray = []; for (var i = 0; i < blob.length; i++) blobArray.push(blob[i]); var result = base64EncodeBytes({ array: blobArray });
Regards,
Constantine
I was indeed very close! Thank you very much :)