Hi Bruce,
The solution above works with 'text' type of file. You have binary type with base64 encoding.
For this case - you should use following approach:
Add new JS asset.
Populate it with following JS code:
Details: http://prntscr.com/5f530x/directprecode
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType '';
sliceSize = sliceSize 512;var byteCharacters = atob(b64Data);
var byteArrays = [];for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);Code: Select all
var byteNumbers = new Array(slice.length); for (var i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } var byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray);
}
Code: Select all
var blob = new Blob(byteArrays, {type: contentType});
return blob; }
/code/pre
Replace following JS code(from implementation above):
pre
//Here you can specify needed fileContent.
var fileContent = 'Hi';
//where "testFileName.txt" is your attach file name.
var fileName = 'ZZZ.txt';
var blob = new Blob([fileContent], { type: "text/xml"});/pre
with below one:
pre
//Here you can use your base64 content. Note: there is no "data:image/jpeg;base64," part.
var base64Content = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
var fileBlob = b64toBlob(base64Content, "image/png");/pre
So in this part of code you will create blob from base64 binary. Note, you should use base64 without "data:image/jpeg;base64," also you should pass file type to second line of the code.
Regards.