Sub Process_Globals
Private HttpClient As HttpClient
Private FileName As String
Private FileUrl As String
Private AccessToken As String
End Sub
Sub AppStart
' Initialize the HttpClient
HttpClient.Initialize("HttpClient")
' Set the Koofr API access token (replace with your token)
AccessToken = "your-koofr-api-access-token"
' Define the URL for the file you want to download
' You need the correct file URL from Koofr
FileUrl = "https://api.koofr.net/v2/files/download?path=%2Fpath%2Fto%2Fyour%2Ffile.txt"
' Define where to save the file locally
FileName = File.DirDocuments & "/downloaded_file.txt"
' Send the HTTP request to download the file
DownloadFileFromKoofr(FileUrl)
End Sub
Sub DownloadFileFromKoofr(url As String)
' Create an HTTP request with the necessary authorization header
Dim req As HttpRequest
req.InitializeGet(url)
req.SetHeader("Authorization", "Bearer " & AccessToken)
' Make the HTTP request to download the file
HttpClient.Send(req)
End Sub
Sub HttpClient_ResponseSuccess (Response As HttpResponse)
' This sub will be called when the file is successfully downloaded
Dim InputStream As InputStream = Response.GetAsStream
Dim File As OutputStream
File = File.OpenOutput(File.DirDocuments, "downloaded_file.txt", False)
' Write the content to the local file
File.WriteFromSameThread(InputStream)
File.Close
Log("File downloaded successfully!")
End Sub
Sub HttpClient_ResponseError (Response As HttpResponse)
' This sub will be called if there was an error downloading the file
Log("Error: " & Response.ErrorMessage)
End Sub