Android : get picture from FTP server then convert to Bitmap in Android

on Saturday, January 31, 2015


Based on an answer on this thread, we can upload and download from FTP server:



//UPLOAD
try
{
FTPClient con = new FTPClient();
con.connect("192.168.2.57");

if (con.login("Administrator", "KUjWbk"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = "/sdcard/vivekm4a.m4a";

FileInputStream in = new FileInputStream(new File(data));
boolean result = con.storeFile("/vivekm4a.m4a", in);
in.close();
if (result) Log.v("upload result", "succeeded");
con.logout();
con.disconnect();
}
}
catch (Exception e)
{
e.printStackTrace();
}

//DOWNLOAD
try
{
FTPClient con = new FTPClient();
con.connect("192.168.2.57");

if (con.login("Administrator", "KUjWbk"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = "/sdcard/vivekm4a.m4a";

OutputStream out = new FileOutputStream(new File(data));
boolean result = con.retrieveFile("vivekm4a.m4a", out);
out.close();
if (result) Log.v("download result", "succeeded");
con.logout();
con.disconnect();
}
}
catch (Exception e)
{
Log.v("download result","failed");
e.printStackTrace();
}


In download part, is it possible to just retrieve the file (assuming the file is always jpg) and convert it to Bitmap without having to create a file in my application's folder?


0 comments:

Post a Comment