1
所以我的程序是從手機中選擇一個圖像,然後我想上傳到我有一個ftp。我知道FTP連接工作,我可以通過去文件管理器成功上傳文件。我的問題是,當我選擇我的手機圖像檢測地址爲:圖像不會上傳到FTP
/external/images/media/34
,但是當我上傳它的logcat說文件不存在:
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)
很明顯它的東西處理文件路徑。 有人知道如何所以選擇該文件,並拿起一個合適的地址 這裏是採摘的文件我的代碼解決這個問題:
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);
}
和這裏就是我把它上傳到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();
}