Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private http As HttpJob
Private FilePath As String
Private FileName As String
Private partSize As Int = 100 * 1024 * 1024 ' 100 Mo en octets
Private partIndex As Int = 0
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
FilePath = "/mnt/sdcard/Download/"
FileName = "MyFile.zip"
SplitAndUpload(FilePath, FileName)
End Sub
Sub SplitAndUpload(F_Path As String, F_Name As String)
Dim raf As RandomAccessFile
raf.Initialize(F_Path, F_Name, False)
Dim totalSize As Int = raf.Size
Dim buffer(partSize) As Byte
Dim offset As Int = 0
Do While offset < totalSize
Dim bytesRead As Int = Min(partSize, totalSize - offset)
raf.ReadBytes(buffer, 0, bytesRead, offset)
Dim partName As String = "part_" & partIndex & ".zip"
Dim partPath As String = File.DirDefaultExternal & "/" & partName
File.WriteBytes(partPath, partName, buffer)
UploadFile(partPath, partName)
offset = offset + bytesRead
partIndex = partIndex + 1
Loop
raf.Close
End Sub
Sub UploadFile(partPath As String, partName As String)
http.Initialize("upload", Me)
http.PostMultipart("https://YouServer.com/upload", CreateMap("file" : partPath), Array(partName))
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success Then
Log("Upload successful : " & Job.GetString)
Else
Log("Error while uploading : " & Job.ErrorMessage)
End If
Job.Release
End Sub