diff --git a/javascript/src/utilities/signingUtilities.js b/javascript/src/utilities/signingUtilities.js index ec255299e58fe5b77311be8f3a128bd646f22c31..20f64f0d273ceeb9fcc92c1542882b324fb6b699 100644 --- a/javascript/src/utilities/signingUtilities.js +++ b/javascript/src/utilities/signingUtilities.js @@ -1495,6 +1495,9 @@ export class ImageData { this.content = null; // Uint8Array: decoded content this.contentBase64 = null; // string: base64 encoded content + if (typeof parameters === "string" || parameters instanceof String) { + this.fromDataURL(parameters); + } else if (typeof parameters === "object") { this.fromParameters(parameters); } @@ -1517,13 +1520,24 @@ export class ImageData { this.getContentBase64(); } - //fromDataURL() + fromDataURL(dataURL) { + if (dataURL.startsWith("data:")) { + const idx = dataURL.indexOf(";base64,"); + if (idx > 0) { + this.contentType = dataURL.substring(5, idx); // 5 = len("data:") + this.contentBase64 = dataURL.substring(idx + 8); // 8 = len(";base64,") + } + } + } //fromContentTypeAndContentAsByteArray() toDataURL() { return "data:" + this.contentType + ";base64," + this.getContentBase64(); } + /** + * @returns {ByteArray} + */ getContent() { if (!this.content) { if (this.contentBase64) { @@ -1533,6 +1547,9 @@ export class ImageData { return this.content; } + /** + * @returns {String} + */ getContentBase64() { if (!this.contentBase64) { if (this.content) {