B4J Tutorial AsyncStreamsObject - Send and receive objects over the network

Douglas Farias

Expert
Licensed User
Longtime User
Ok, but AStreamO_NewObject on the b4a dont save the file, only give logs.

1° i m sending the key file:myfilename from b4j its correct now

2° on the b4a i m get this in AStreamO_NewObject with substring , this is ok

B4X:
Sub astreamO_NewObject(Key As String, Value As Object)
    If Key.StartsWith("arquivo:") Then
    Log(Key.SubString(8))
            Dim fileName As String = Value
            Log(fileName)
            Log("Received file. File size: " & File.Size(astreamO.TempFolder, fileName))
  End If
   
End Sub

but the problem is how to write a file with this name now, the astreamO_NewObject dont save the file, i think this code is in your class on b4a.
i m sending the correct name, i m geting this correct name on b4a, and now how to save the file with correct name?
 

Attachments

  • Sem título.png
    209.7 KB · Views: 546

Douglas Farias

Expert
Licensed User
Longtime User
done, i have made this
B4X:
    If Key.StartsWith("arquivo:") Then
    Log(Key.SubString(8))
            Dim fileName As String = Value
            File.Copy(astreamO.TempFolder,fileName, fp , Key.SubString(8))
            Log(File.ListFiles(fp))
    End If
ty @Erel
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
when i use this code, with big files, i have a small bug

B4X:
If Key.StartsWith("arquivo:") Then
            Dim fileName As String = Value
            log("aqui")
            File.Copy(astreamO.TempFolder,fileName, fp , Key.SubString(8))
            Log("done")
    End If

for exemple, send from pc a video with 60mb, on the b4a it make a laggg when make this File.Copy
i see the log "aqui" like the code. log("aqui")

my app stop respose for 5 or 10 seconds, i have try make this


B4X:
If Key.StartsWith("arquivo:") Then
            Dim fileName As String = Value
            log("aqui")
            ProgressDialogShow2("carregando...", False)
            DoEvents
            File.Copy(astreamO.TempFolder,fileName, fp , Key.SubString(8))
            Log("done")
    End If

but dont work with doevents, my app stop response too with
B4X:
ProgressDialogShow2("carregando...", False)
         DoEvents

and i dont see the ProgressDialogShow2 only the log "aqui"

and later my app stop work for 5 - 10 seconds i see "Done" the last log.

now the question, why this? i m know the file is bigger 60mb, but have a way to my app dont stop work when make a file.copy?
and how can i add a progress on this? ProgressDialogShow2("Copying...", False), later done ProgressDialogHide
 

Douglas Farias

Expert
Licensed User
Longtime User
why use a library to make a sub? can u give a simple example code?

callsubcopy(folders, file)

sub copy
file.copy
end sub
 

Douglas Farias

Expert
Licensed User
Longtime User
this dont helped my @Erel
look i made this

B4X:
        'VIDEOS
        Else If Key.SubString(8).StartsWith("videos:") Then
        Dim fileName As String = Value
        File.MakeDir(fp, "Videos")
        pasta = File.Combine(fp, "Videos")
        ProgressDialogShow2("carregando...", False)
        Private l As List
        l.Initialize
        l.AddAll(Array As String(astreamO.TempFolder, fileName, pasta, Key.SubString(15)))
        TR.RunOnGuiThread("copiar_arquivos" , Array As Object(l))


Sub copiar_arquivos(MapObj As Object)
Private l As List
l.Initialize
l = MapObj
File.Copy(l.Get(0), l.Get(1), l.Get(2), l.Get(3))
ProgressDialogHide
End Sub

but my app stop work too with RunOnGuiThread.
only with big sizes the app stop works, 60mb+

EDIT: 03:06
B4X:
        'VIDEOS
        Else If Key.SubString(8).StartsWith("videos:") Then
        Dim fileName As String = Value
        File.MakeDir(fp, "Videos")
        pasta = File.Combine(fp, "Videos")
        Private l As List
        l.Initialize
        ProgressDialogHide
        ProgressDialogShow2("Copiando...", False)
        l.AddAll(Array As String(astreamO.TempFolder, fileName, pasta, Key.SubString(15)))
        TR.Start(Me, "copiar_arquivos" , Array As Object(l))

this code works, with tr.start

thx erel
 
Last edited:

YIM bunchhat

Active Member
Licensed User
Longtime User
I cannot send file and receive file. How to send file from phone to pc? Ex: file .pdf in sd card...... Could you write me simple code that work only send file from phone to PC? your example is complicated for me.......now I am really headache...
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…