Skip to content

Commit a9794a8

Browse files
committed
fix(nanoflow-commons-native): synchronization issue with Base64 images
1 parent 8d8c994 commit a9794a8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/jsActions/nanoflow-actions-native/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We've fixed a synchronization issue with Base64 images generated by the Signature widget.
12+
913
### Changed
1014

1115
- We've updated the minimum Mendix version to 10.21.

packages/jsActions/nanoflow-actions-native/src/other/Base64DecodeToImage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { Base64 } from "js-base64";
98

109
// BEGIN EXTRA CODE
1110
// END EXTRA CODE
@@ -16,7 +15,7 @@ import { Base64 } from "js-base64";
1615
* @param {MxObject} image
1716
* @returns {Promise.<boolean>}
1817
*/
19-
export function Base64DecodeToImage(base64: string, image: mendix.lib.MxObject): Promise<boolean> {
18+
export async function Base64DecodeToImage(base64: string, image: mendix.lib.MxObject): Promise<boolean> {
2019
// BEGIN USER CODE
2120

2221
if (!base64) {
@@ -26,7 +25,10 @@ export function Base64DecodeToImage(base64: string, image: mendix.lib.MxObject):
2625
throw new Error("image should not be null");
2726
}
2827

29-
const blob = new Blob([Base64.toUint8Array(base64)], { type: "image/png" });
28+
const dataUri = base64.startsWith("data:") ? base64 : `data:image/png;base64,${base64}`;
29+
30+
const res = await fetch(dataUri);
31+
const blob = await res.blob();
3032

3133
return new Promise((resolve, reject) => {
3234
mx.data.saveDocument(image.getGuid(), "camera image", {}, blob, () => resolve(true), reject);

0 commit comments

Comments
 (0)