I have the need to send images from my local server to a server on the interwebz.
Windows and WebApp Application are in DF 18.2. My windows application is running a ClientWebService (cWSTransactionService.pkg ) to sync database entries between local and web server.
In order to test this (optimization will happen after I get this running), I extended the procedure that updates the location record to find all images and use a loop to write a Base64String to be send with that record.
Code:
Integer iFileCount iLoopCount iArraySize iArgSize
String sHomePath sLogPath sSourcePath
DateTime dtNow
//
If (Length(Trim(Location.Image1))>=1) Begin
Increment iDItem
Move (Trim(Location.Image1)) to tUpdate[iItems].tLocImages[iDItem].sFileName
End
If (Length(Trim(Location.Image2))>=1) Begin
Increment iDItem
Move (Trim(Location.Image2)) to tUpdate[iItems].tLocImages[iDItem].sFileName
End
If (Length(Trim(Location.Image3))>=1) Begin
Increment iDItem
Move (Trim(Location.Image3)) to tUpdate[iItems].tLocImages[iDItem].sFileName
End
If (Length(Trim(Location.Image4))>=1) Begin
Increment iDItem
Move (Trim(Location.Image4)) to tUpdate[iItems].tLocImages[iDItem].sFileName
End
If (Length(Trim(Location.Image5))>=1) Begin
Increment iDItem
Move (Trim(Location.Image5)) to tUpdate[iItems].tLocImages[iDItem].sFileName
End
//
Get psHome of (phoWorkspace(ghoApplication)) to sHomePath
Move (sHomePath+"Bitmaps\Snowbooks\") to sSourcePath
Move (sHomePath+"Document\Log\SnowbookImg.log") to sLogPath
Move (CurrentDateTime()) to dtNow
Get_Argument_Size to iArgSize
//
Move (SizeOfArray(tUpdate[iItems].tLocImages)-1) to iArraySize
If (iArraySize>1) Begin
For iLoopCount from 1 to iArraySize
Send Base64EncodeFile sSourcePath tUpdate[iItems].tLocImages[iLoopCount].sFileName (&tUpdate[iItems].tLocImages[iLoopCount].iEncodeBinSize) (&tUpdate[iItems].tLocImages[iLoopCount].sEncodeString)
Loop
End
Base64EncodeFile takes passed info and encodes the file to a String. Since most files are >64kb, I adjust the ArgumentSize before each time this is executed, and reset it to 64kb after its completed.
Code:
Procedure Base64EncodeFile String sSourcePath String sFileName Integer ByRef iEncodeBinSize String ByRef sEncodeString
Address aEncodeBuffer
// ENCODE
Get ReadBinFileToBuffer of oSeqFileHelper1 (sSourcePath+sFileName) (&iEncodeBinSize) to aEncodeBuffer
Set_Argument_Size 5242880 // 5MB
Get Base64EncodeToStr of oCharTranslate aEncodeBuffer iEncodeBinSize to sEncodeString
End_Procedure
On the receiving web server, in the procedure that updates the location record, I added code to DECODE the transmitted images.
Code:
//Update Images from Base64
String sHomePath sLogPath sTargetPath
Integer iArraySize iLoopCount iArgSize
Get psHome of (phoWorkspace(ghoApplication)) to sHomePath
Move (sHomePath+"Bitmaps\Snowbooks\") to sTargetPath
Move (sHomePath+"Document\Log\SnowbookImg.log") to sLogPath
Move (SizeOfArray(tLocationUpdate[iItem].tLocImages)-1) to iArraySize
If (iArraySize>=1) Begin
For iLoopCount from 1 to iArraySize
Get_Argument_Size to iArgSize
//Set_Argument_Size (tLocationUpdate[iItem].tLocImages[iLoopCount].iEncodeBinSize*2) //Set ArgSize to required and recomnended size of twice the file size - DOES NOT WORK?
Set_Argument_Size 5242880 // 5MB
Send Base64DecodeFile sTargetPath tLocationUpdate[iItem].tLocImages[iLoopCount].sFileName tLocationUpdate[iItem].tLocImages[iLoopCount].iEncodeBinSize tLocationUpdate[iItem].tLocImages[iLoopCount].sEncodeString
Set_Argument_Size iArgSize
Loop
End
And to decode the file:
Code:
Procedure Base64DecodeFile String sDecodePathOfFile String sFileName Integer iEncodeBinSize String sDecodeString
String sTargetPathFile
Address aDecodeBuffer
Integer iDecodeBinSize iVoid
// DECODE
Get Base64DecodeFromStr of oCharTranslate sDecodeString (&iDecodeBinSize) to aDecodeBuffer
If (iEncodeBinSize <> iDecodeBinSize) Begin
//Send Info_Box "Test Failed"
End
Else Begin
Move (sDecodePathOfFile+Trim(sFileName)) to sTargetPathFile
Send WriteBinFileFromBuffer of oSeqFileHelper1 sTargetPathFile aDecodeBuffer iDecodeBinSize
End
Move (Free(aDecodeBuffer)) to iVoid
End_Procedure
I have tested this successfully with files 41kb. As soon as I use 1+MB the files are not getting transmitted.
Am I using Set_Argument_Size not correctly?
Is there something besides a String to use to send larger files across the web?
Kind regards, Ben