Hello, I ask for help over rising image for ftp, which is causing me some small problems, it turns out upload images to the server and if the image up correctly update a field in the database of the phone with value 1 and also updated with value 1 bd MySQL Server.
The problem is that sometimes the image does not rise up and take it as correct even if it is not raised, there will be another way to check the rise.
Here is the code that I have to see if anyone is aware of this.
Thanks for your time.
The problem is that sometimes the image does not rise up and take it as correct even if it is not raised, there will be another way to check the rise.
Here is the code that I have to see if anyone is aware of this.
B4X:
Sub SubeImagen1 'SUBE IMAGEN1 AL SERVIDOR
Dim MyPath As String
MyPath = File.DirRootExternal & "/Carga/" 'PREGUNTA SI EL DIRECTORIO EXISTE
If File.Exists(MyPath, "") = False Then
ToastMessageShow("La ruta no existe", True)
Else
s.BeginTransaction
c = s.ExecQuery("SELECT id_registro, id_telefono, id_usuario, image_km FROM registro WHERE id_registro <> 0 AND sync_img1 = 0 LIMIT 1")
If c.RowCount <> 0 Then
For i = 0 To c.RowCount-1
c.Position = i
'FTP.SendCommand("MKD", "/"&c.GetString("id_controlvar")) 'CREA CARPETA EN EL SERVIDOR
ImagenSelec = c.GetString("image_km")
IdRegistro = c.GetString("id_registro")
FTP.UploadFile(MyPath, ImagenSelec, False, "/img/"&ImagenSelec) 'SUBE IMAGEN AL SERVIDOR
NumImg = 1
NumNoti = NumNoti + 1
Next
Else
SubeImagen2
End If
s.TransactionSuccessful
s.EndTransaction
End If
End Sub
B4X:
Sub SubeImagen2 'SUBE IMAGEN2 AL SERVIDOR
Dim MyPath As String
MyPath = File.DirRootExternal & "/Carga/" 'PREGUNTA SI EL DIRECTORIO EXISTE
If File.Exists(MyPath, "") = False Then
ToastMessageShow("La ruta no existe", True)
Else
s.BeginTransaction
c = s.ExecQuery("SELECT id_registro, id_telefono, id_usuario, image_lt FROM registro WHERE id_registro <> 0 AND sync_img2 = 0 LIMIT 1")
If c.RowCount <> 0 Then
For i = 0 To c.RowCount-1
c.Position = i
'FTP.SendCommand("MKD", "/"&c.GetString("id_controlvar")) 'CREA CARPETA EN EL SERVIDOR
ImagenSelec = c.GetString("image_lt")
IdRegistro = c.GetString("id_registro")
FTP.UploadFile(MyPath, ImagenSelec, False, "/img/"&ImagenSelec) 'SUBE IMAGEN AL SERVIDOR
NumImg = 2
NumNoti = NumNoti + 1
Next
End If
s.TransactionSuccessful
s.EndTransaction
End If
End Sub
B4X:
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
Dim upload As String
'upload = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
upload = Round(TotalUploaded / 1000) & "KB"
If Total > 0 Then upload = upload & " out of " & Round(Total / 1000) & "KB"
Log(upload)
'ToastMessageShow(upload, True)
'=======================Notificación===============================
notif.Initialize
notif.Light = False
notif.Vibrate = False
notif.OnGoingEvent = False
notif.Sound = False
notif.Icon = "uploaded"
notif.SetInfo("Carga de Imagen ", "Subiendo imagen"&" "&upload, "")
notif.Notify(NumNoti)
'=======================Fin Notificación===============================
End Sub
B4X:
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = False Then Log(LastException.Message)
If Success = True Then
If NumImg == 1 Then
s.ExecNonQuery2("UPDATE registro SET sync_img1 = ? WHERE id_registro = '" & IdRegistro & "'", Array As Object(1))
GetData("UPDATE registro SET sync_img1 = 1 WHERE id_registro ='" & IdRegistro & "' AND sync_img1 = 0;", "GetUPD")
End If
If NumImg == 2 Then
s.ExecNonQuery2("UPDATE registro SET sync_img2 = ? WHERE id_registro = '" & IdRegistro & "'", Array As Object(1))
GetData("UPDATE registro SET sync_img2 = 1 WHERE id_registro ='" & IdRegistro & "' AND sync_img2 = 0;", "GetUPD")
End If
'ToastMessageShow("Imagen subida correctammente", True)
'notif.Vibrate = True
'notif.Sound = True
notif.SetInfo("Carga de imagen", "Finalizada", "")
notif.Notify(NumNoti)
If NumImg = 1 Then
NumImg = 0
SubeImagen1
End If
If NumImg == 2 Then
NumImg = 0
SubeImagen2
End If
Else
ToastMessageShow("Subida imagen fracasada", False)
If NumImg == 1 Then
NumImg = 0
SubeImagen1
End If
If NumImg == 2 Then
NumImg = 0
SubeImagen2
End If
End If
End Sub
Thanks for your time.