WebServices and Base64 string

634 views
Skip to first unread message

Antony Georgopoulos

unread,
Oct 1, 2020, 10:34:01 AM10/1/20
to Softone Developers Network
Hello all


I am trying to send an image file from Softone Webservices as a base64 string.

I have searched the Black Book but I cant find something to help me.  

Is there any function that can change a binary to base64 or should I try to create an S1 Sql Script.


Thanks in advance






Νίκος Μάλιακκας

unread,
Oct 30, 2020, 12:54:30 PM10/30/20
to Softone Developers Network
I am using theese two functions to read/write from binary fields using base64 string
one can use them in Advanced Javascript Module like this:
function testUploadPicture(injson){
X.RUNSQL("INSERT INTO XTRDOCDATA (REFOBJID, SOSOURCE , LNUM, LINENUM, SODATA ) VALUES (" + injson.mtrl + ", 51, 0 , 1 , dbo.f_Base64ToBinary('" + injson.sodataB64 + "') )", null);
}

The read function can be used from SQLScripts and from ws using SQLData (https://softone.gr/ws/#SqlData)


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO  

CREATE FUNCTION [dbo].[f_Base64ToBinary](@Base64 VARCHAR(MAX))
RETURNS VARBINARY(MAX)
AS
BEGIN
DECLARE @Bin VARBINARY(MAX)

SET @Bin = CAST(N'' AS XML).value('xs:base64Binary(sql:variable("@Base64"))', 'VARBINARY(MAX)')

RETURN @Bin
END
GO



 
CREATE FUNCTION [dbo].[f_BinaryToBase64](@bin VARBINARY(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Base64 VARCHAR(MAX)

SET @Base64 = CAST(N'' AS XML).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))','VARCHAR(MAX)')

RETURN @Base64
END
GO  
Reply all
Reply to author
Forward
0 new messages