iOS Question iNMSSH - SFTP Upload files

RaymondHung

Member
Licensed User
Longtime User
Hi Erel
My code uses "InitCamera" to select image files, and then upload files via iNMSSH SFTP, but if you don't know the file name and path, you cannot upload it. If I have an error, please advise.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private cam As Camera
    Private sftp1 As NMSSH
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("main")
    NavControl.ShowPage(Page1)
    sftp1.Initialize("sftp1")
End Sub

Sub InitCamera
    cam.Initialize("cam", Page1)
End Sub

Sub btnOpenFile_Click
    InitCamera
    cam.SelectFromPhotoLibrary(Sender, cam.TYPE_IMAGE)   
End Sub

Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)   
    If Success Then
        If Image.IsInitialized Then   
            'File name ?????
            'File path ?????
           sftp1.UploadFile(File path, File name, "/File name")       
           Wait For sftp1_UploadCompleted (success As Boolean)
        End If
    End If
End Sub
 
Upvote 0

RaymondHung

Member
Licensed User
Longtime User
Is it possible to know the name and path of the Add File in ios?
I want to achieve the following android UI effect.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
try this:

B4X:
Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
    If Success Then
        If Image.IsInitialized Then
            Dim folder As String = File.DirDocuments
            Dim filename As String = "myFile.jpg"
            saveAndUploadFile(Image,folder,filename)
        End If
    End If
End Sub

Sub saveAndUploadFile(bmp As Bitmap,folder As String, fileName As String)
    'first we need to save the file
    Dim Out As OutputStream
    Out = File.OpenOutput(folder,fileName, False)
    bmp.WriteToStream(Out, 100, "JPEG")
    Out.Close
    
    'now we can upload it
    sftp1.UploadFile(folder, fileName, "/File name")
    Wait For sftp1_UploadCompleted (Success As Boolean)
    '...
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…