I am trying to create a routine to download a file and open it with the default app for file type
This is what I have created so far but I get an error "Forbidden You don't have permission......"
url is something like "www.mysite.com/dir1/dir2/myfile.pdf"
My attempt
This is what I have created so far but I get an error "Forbidden You don't have permission......"
url is something like "www.mysite.com/dir1/dir2/myfile.pdf"
My attempt
B4X:
Sub DownloadFile(url As String)
Dim job As HttpJob
job.Initialize("DownloadJob", Me)
job.Username = "xxxxx" ' Replace with your actual username
job.Password = "*****" ' Replace with your actual password
job.Download(url)
Dim fname As String = url.SubString(url.LastIndexOf("/")+1)
Log(fname)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
' Save the downloaded file
Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, fname, False)
File.Copy2(job.GetInputStream, out)
out.Close
Else
Log("Error downloading file: " & job.ErrorMessage)
End If
job. Release
End Sub