Skip to main content

I just using the next vba code to download a file, but when i do "http.send", the error -2147024891(80070005) is showed in the message box and the vba code goes error end, looks like api abort.

Sub DownloadFromBox()
    Dim http As Object
    Dim url As String
    Dim filePath As String
    
    ' API endpoint URL
    Dim FileId As String
    FileId = "File_id"
    url = "https://api.box.com/2.0/files/" & FileId & "/content"
    
    ' save file path
    filePath = "c:\temp\downloadtest.log"
    
    ' HTTP request
    Set http = CreateObject("MSXML2.XMLHTTP")
    
    Dim token As String
    token = "my_devloper_token"   'Ps:this token is copyed from my application setting
    http.Open "GET", url, False
    http.setRequestHeader "Authorization", "Bearer " & token
    http.send


    ' save file
    If http.Status = 200 Then
        Dim stream As Object
        Set stream = CreateObject("ADODB.Stream")
        stream.Type = 1
        stream.Open
        stream.Write http.responseBody
        stream.SaveToFile filePath, 2 ' 2 = overwrite
        stream.Close
        MsgBox "download succeed"
    Else
        MsgBox "error: " & http.Status & " - " & http.statusText
    End If
    
    Set http = Nothing
    Set stream = Nothing
End Sub

Hi Ji, 


Welcome to Box Community and glad to assist! 


To answer your inquiry, you can take it to our Developer team by posting it to community.box.com


We'd love to further assist! 


Reply