I have a question about the times when deleting files after uploading them to an FTP server.
Let me explain, I have the following function, which uploads a file hosted on the mobile device to an FTP server and, when it finishes, calls a method that deletes it from the device.
Method that uploads image to FTP server
public void upLoadPicture() {
try {
FTPClient client2 = new FTPClient();
client2.connect("192.168.0.26");
client2.login("xxxx", "123");
client2.setPassive(true);
client2.setType(FTPClient.TYPE_BINARY);
File dir = Environment.getExternalStorageDirectory();
String filename = dir.getAbsolutePath()+"prueba.jpg";
File f = new File(filename);
client2.upload(f);
client2.disconnect(true);
//Llama al método para borrar la imagen del móvil
Borra_imagen_dispositivo();
} catch (Exception e) {
Toast.makeText(this, "Error al conectar", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
Method that erases the image after uploading it
private void Borra_imagen_dispositivo(){
File dir = Environment.getExternalStorageDirectory();
String filename = dir.getAbsolutePath()+"prueba.jpg";
File file = new File(filename);
file.delete();
}
My question is, when it comes to images of a certain size, the upload usually takes a few seconds to complete, therefore, would there be a risk that the file will be deleted before it finished uploading the image? Should I sleep the call to the method Borra_imagen_device () for a while to make sure, for example using Thread.sleep or similar methods? Thanks