Android Question Send image

Alisson

Active Member
Licensed User
I try send images to FTP server:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ftp1 As FTP
    Dim btninvio As Button
    Dim btncarica As Button
    Dim btncancella As Button
    Dim Arquivo As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("tutorial")
 

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btninvio_Click
    Arquivo = File.ListFiles("/storage/emulated/0/Android/data/folder/cache/")
    For i = 0 To Arquivo.Size - 1
    ftp1.Initialize("ftp1","ftp.address.com","21","root","string")
    Msgbox(Arquivo.Get(i),"")
    ftp1.UploadFile(File.DirRootExternal,Arquivo.Get(i),False,"/storage/emulated/0/Android/data/nesic.app.report/cache/"&Arquivo.Get(i))
    'tp1.Close 
    Next
End Sub

Sub btncarica_Click
 
End Sub

Sub btncancella_Click
 
End Sub
Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = True Then
        Msgbox("","")
     
    End If
End Sub




'End Sub

The code read all images, but not send to server.
I think the problem is here File.DirRootExternal.

Thanks very much!
 

DonManfred

Expert
Licensed User
Longtime User
I think the problem is here File.DirRootExternal.
The proglem is in youir brain
You are getting a list of files from the folder
"/storage/emulated/0/Android/data/folder/cache/"
and want to upload them... WHY are you using File.DirRootExternal as path then?
The source path is "/storage/emulated/0/Android/data/folder/cache/"

ftp1.UploadFile(File.DirRootExternal,Arquivo.Get(i),False,"/storage/emulated/0/Android/data/nesic.app.report/cache/"&Arquivo.Get(i))
There is a path-structure like "/storage/emulated/0/Android/data/nesic.app.report/cache/" on the destination ftp-server? If not (what i would expect); why are you trying to upload to this path?
 
Last edited:
Upvote 0

Alisson

Active Member
Licensed User
I forget change the path in the thread.
My code correct:


B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ftp1 As FTP
    Dim btninvio As Button
    Dim btncarica As Button
    Dim btncancella As Button
    Dim Arquivo As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("tutorial")
 

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btninvio_Click
    Arquivo = File.ListFiles("/storage/emulated/0/Android/data/nesic.app.report/cache/")
    ' I read the images
 
    For i = 0 To Arquivo.Size - 1   ' for to catch images
    ftp1.Initialize("ftp1","ftp.address.com","21","user","pass")   ' connect to FTP
    ftp1.UploadFile(File.DirRootExternal,Arquivo.Get(i),False,Arquivo.Get(i))       
    'Send images
 
    Next
End Sub

Sub btncarica_Click
 
End Sub

Sub btncancella_Click
 
End Sub
Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = True Then
        Msgbox("","")
     
    End If
End Sub




'End Sub
DonManfred, I change the path, but the same error continue, no send images. :(
 
Upvote 0

Alisson

Active Member
Licensed User
DonManfred, not send the image.
Erel... I change to process_globals, but continue not send.
I attachement my app.
I don't know the error!
 

Attachments

  • ftp.zip
    7.8 KB · Views: 184
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
DonManfred, not send the image.
You are running the same problematic code like in the beginning of the thread.

You are STILL initializing the ftp each time!

You are STILL using the TOTAL WRONG Path when uploading.... Reading from path A but want to upload the files from path B

B4X:
Sub btninvio_Click
    Arquivo = File.ListFiles("/storage/emulated/0/Android/data/nesic.app.report/cache/")
    For i = 0 To Arquivo.Size - 1
    ftp1.Initialize("ftp1","ftp.corporation.com","21","corporation","password")
  
    ftp1.UploadFile(File.DirRootExternal,Arquivo.Get(i),False,Arquivo.Get(i))
    'tp1.Close  
    Next
End Sub

I´m out here! Don´expect more help from me. I Give up against this amount of ignorance!
 
Upvote 0

Alisson

Active Member
Licensed User
Thanks very much by help.

I Try use all the tip to code, but not have success.

1º My first one cellphone sttoped application in the List.

2º The other cellphone read the image and path correctily, but return the warning: "not found" when I try to upload the file.

Thanks LucaMs.

DonManfred, I try all possible to excute the code, but not have success. I not ignore your tip.
Just pressed CTRL + Z to return to the initial code.

Thanks
 
Upvote 0
Top