Last active
August 4, 2022 09:35
-
-
Save grongierisc/c1ce358fbb78fe5f292a5560483742e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2021 by InterSystems Corporation. | |
Cambridge, Massachusetts, U.S.A. All rights reserved. | |
Confidential property of InterSystems Corporation. */ | |
Class PEX.Msg.Message Extends (Ens.MessageBody, %CSP.Page, %XML.Adaptor) | |
{ | |
Property Base64Image As %Stream.GlobalCharacter; | |
Property BinaryImage As %Stream.GlobalBinary; | |
/// This method is called by the Management Portal to determine the content type that will be returned by the <method>%ShowContents</method> method. | |
/// The return value is a string containing an HTTP content type. | |
Method %GetContentType() As %String | |
{ | |
Quit "text/html" | |
} | |
/// This method is called by the Management Portal to display a message-specific content viewer.<br> | |
/// This method displays its content by writing out to the current device. | |
/// The content should match the type returned by the <method>%GetContentType</method> method.<br> | |
Method %ShowContents(pZenOutput As %Boolean = 0) | |
{ | |
set MaxStringLength = 3640044 | |
if ..Base64Image.Size > 0 { | |
&html<<div>Base64Image<div>> | |
&html<<img src="data:image/jpeg;base64,#(..Base64Image.Read(MaxStringLength))#" width="100%">> | |
} | |
if ..BinaryImage.Size >0 { | |
&html<<div>BinaryImage<div>> | |
&html<<img src="%25CSP.StreamServer.cls?STREAMOID=#(..Encrypt(..BinaryImage.%Oid()))#" width="100%">> | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import iris | |
from grongier.pex import BusinessProcess | |
class Base64(BusinessProcess): | |
""" | |
> The function receives the base64 string from the Python service, decodes it, and saves it as an | |
image file | |
/irisdev/app/misc/component-config.png | |
""" | |
def run(self,request:'iris.Ens.StringRequest'): | |
""" | |
> The function reads the image file, encodes it as a base64 string, and sends it to the Python | |
service | |
:param request: The request object that was sent to the operation | |
:type request: 'iris.Ens.StringRequest' | |
""" | |
with open(request.StringValue, "rb") as image_file: | |
binary = image_file.read() | |
encoded_string = base64.b64encode(binary) | |
msg = iris.cls('PEX.Msg.Message')._New() | |
n = 3600 | |
chunks = [binary[i:i+n] for i in range(0, len(binary), n)] | |
for chunk in chunks: | |
msg.BinaryImage.Write(chunk) | |
chunks = [encoded_string[i:i+n] for i in range(0, len(encoded_string), n)] | |
for chunk in chunks: | |
msg.Base64Image.Write(chunk) | |
self.send_request_sync('Python.HeartBeatOperation',msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment