Sample code for 30+ languages & platforms
DataFlex

Box.com Download Binary File to Memory

See more Box Examples

Retrieves the actual data of the file into a memory (not to a local file).

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vBd
    Handle hoBd
    Integer iStatusCode
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComKeepResponseBody Of hoHttp To True

    // Provide a previously obtained OAuth2 access token.
    // See Get Box OAuth2 Access Token.
    Set ComAuthToken Of hoHttp To "BOX_ACCESS_TOKEN"

    Set ComFollowRedirects Of hoHttp To True

    // The file is specified by the file ID.
    // In this case, we're downloading a file with FILE_ID = 283371752129.
    // The general form of the URL for downloading is: https://api.box.com/2.0/files/FILE_ID/content
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get pvComObject of hoBd to vBd
    Get ComDownloadBd Of hoHttp "https://api.box.com/2.0/files/283371752129/content" vBd To iSuccess
    Get ComLastStatus Of hoHttp To iStatusCode
    If (iSuccess = False) Begin
        If (iStatusCode = 0) Begin
            // Unable to either send the request or get the response.
            Get ComLastErrorText Of hoHttp To sTemp1
            Showln sTemp1
        End
        Else Begin
            // We got a response, but the status code was not in the 200s
            Showln "Response status code: " iStatusCode
            // Examine the response body.
            Showln "Response body:"
            Get ComLastResponseBody Of hoHttp To sTemp1
            Showln sTemp1
        End

        Showln "Download failed."

    End
    Else Begin
        Showln "Downloaded tigers.jpeg into an object holding the binary data."

        Get ComNumBytes Of hoBd To iTemp1
        Showln "Number of bytes: " iTemp1
    End



End_Procedure