So my program is selecting an image from the phone and then I want to upload it to an ftp that I have. I know the FTP connection works and I can succesfully upload a document by going to the file manager. My problem is when I select an image from my phone it detects the address as:
/external/images/media/34
but when I am uploading it the logcat says file doesn't exist:
03-09 16:00:32.702 19649-19678/net.azurewebsites.cosy W/System.err﹕ java.io.FileNotFoundException: /external/images/media/34: open failed: ENOENT (No such file or directory)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:409)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:78)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at net.azurewebsites.cosy.AddBook$UploadBook.doInBackground(AddBook.java:460)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at net.azurewebsites.cosy.AddBook$UploadBook.doInBackground(AddBook.java:431)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-09 16:00:32.706 19649-19678/net.azurewebsites.cosy W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
It's obvious it's something to do with the filepath. Anybody know how to fix it so it selects the file and picks up a proper address Here is my code for picking the file:
Intent galleryInent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryInent, RESULT_LOAD_IMAGE);
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data !=null)
{
selectedImage = data.getData();
imageToUpload.setImageURI(selectedImage);
}
and here is where I upload it to the ftp:
if (con.login("cosy\\username", "pass"))
{
Log.v("connection:","Successful");
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = file;
FileInputStream in = new FileInputStream(new File(data));
if(type=="image")
{
con.changeWorkingDirectory("site/wwwroot/images/");
result = con.storeFile(BookName + ".jpg", in);
}
if(type=="file")
{
con.changeWorkingDirectory("site/wwwroot/Books/");
result = con.storeFile(BookName + ".pdf", in);
}
else
{
result =false;
}
in.close();
if (result)
Log.v("upload result", "succeeded");
con.logout();
con.disconnect();
}