Results 1 to 5 of 5

Thread: Sending files to WebApp

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Minneapolis, MN
    Posts
    173

    Default Sending files to WebApp

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,332

    Default Re: Sending files to WebApp

    ...something besides a String: UChar[].

    But it might be a server-side issue: Check out things like Maximum Requesting Entity Body Limit: 200000 bytes by default.

    Mike

  3. #3
    Join Date
    Sep 2011
    Location
    Minneapolis, MN
    Posts
    173

    Default Re: Sending files to WebApp

    Mike,
    So, I adjusted this to use UChar Array, that works.
    Tried it successfully with two 280 KB file, however it took like almost 55 seconds.
    Anything bigger than that, made the service time out, after around 60 sec.

    Both Ethernet adapters seem to just idle at 120 Kbps.

    Any idea why this would be soooo slow?

    PS: Specs
    Specs Local Remote
    Server VM (4Core 2.10 Ghz|10GB| 200GB SSD) VM (2 Core 2.4Ghz|7GB|126GB SSD)
    OS Server 2016 Server 2016
    Internet 1 Gig Fiber 1+ Gig
    Last edited by Benjamin; 26-Sep-2019 at 08:26 AM. Reason: Added Server Specs

  4. #4
    Join Date
    Sep 2011
    Location
    Minneapolis, MN
    Posts
    173

    Default Re: Sending files to WebApp

    Anyone has any idea why this is so slow?

  5. #5
    Join Date
    Feb 2009
    Location
    Adelaide, South Australia, Down under
    Posts
    2,195

    Default Re: Sending files to WebApp

    Are you using post or url variables (get).
    If the latter, increase the maximum allowed url size in IIS.
    Marco Kuipers
    DataFlex Consultant
    28 IT Pty Ltd - DataFlex Specialist Consultancy
    Adelaide, South Australia
    www.28it.com.au

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •