Hi all. I'm having trouble downloading a file from a link (Google Drive and Dropbox shareable link) from my app. Code says Success but the file downloaded is corrupted and unusable.
This is with OKHttpUtils2
The file in Google Drive and Dropbox is 169Kb and the downloaded file ends up with 129Kb.
These are the urls for the file:
I also used DownloadManager Library with the same results:
Any help is appreciated.
This is with OKHttpUtils2
B4X:
j.Initialize("job", Me)
j.Download(modMain.shareableLinkGD) 'or modMain.shareableLinkDB
Sub JobDone(job As HttpJob)
ProgressDialogHide
If job.Success Then
'we can check the of value job.JobName if there is more than one job
'Activity.SetBackgroundImage(job.GetBitmap)
Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, "Songs_DB2.db3", False)
File.Copy2(job.GetInputStream, out)
out.Close
ToastMessageShow("DB Downloaded Successfully", False)
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub
The file in Google Drive and Dropbox is 169Kb and the downloaded file ends up with 129Kb.
These are the urls for the file:
B4X:
Public shareableLinkGD As String = "https://drive.google.com/file/d/1E5er9sJJuuLJg2BCyGmBf91zlHl0srYZ/view?usp=sharing"
Public shareableLinkDB As String = "https://www.dropbox.com/s/9r224aj558j3ioa/Songs_DB.db3?dl=0"
I also used DownloadManager Library with the same results:
B4X:
dm.RegisterReceiver("dm")
If Utils.IsInitialized=False Then
Utils.Initialize(dm)
End If
Dim dmr As DownloadManagerRequest
dmr.Initialize(modMain.shareableLinkGD)
dmr.Description = "Download File " & "Songs_DB2.db3"
dmr.DestinationUri = "file://" & File.Combine(File.DirDefaultExternal, "Songs_DB2.db3")
dmr.Title = "Songs_DB2.db3"
dmr.VisibleInDownloadsUi = True
dID = dm.Enqueue(dmr)
Private Sub dm_DownloadComplete(DownloadId As Long)
If dID = DownloadId Then
Dim DownloadManagerQuery1 As DownloadManagerQuery
DownloadManagerQuery1.Initialize
DownloadManagerQuery1.SetFilterById(DownloadId)
' you must enable the SQL library to work with the Cursor object
Dim StatusCursor As Cursor
' pass our DownloadManagerQuery to the DownloadManager
StatusCursor=dm.Query(DownloadManagerQuery1)
If StatusCursor.RowCount > 0 Then
StatusCursor.Position = 0
Dim StatusInt As Int
StatusInt = StatusCursor.getInt(dm.COLUMN_STATUS)
Log("Download Status = " & Utils.GetStatusText(StatusInt))
If StatusInt = dm.STATUS_FAILED Or StatusInt = dm.STATUS_PAUSED Then
Dim ReasonInt As Int
ReasonInt = StatusCursor.GetInt(dm.COLUMN_REASON)
Log("Status Reason = " & Utils.GetReasonText(ReasonInt))
End If
If StatusInt = dm.STATUS_SUCCESSFUL Then
'ImageView1.Bitmap=LoadBitmap(File.DirRootExternal, DOWNLOAD_FILENAME)
End If
Else
' always check that the Cursor returned from the DownloadManager Query method is not empty
Log("The DownloadManager has no trace of our request, it could have been cancelled by the user using the Android Downloads app or an unknown error has occurred.")
End If
' free system resources
StatusCursor.Close
dm.UnregisterReceiver
End If
ProgressDialogHide
End Sub
Any help is appreciated.