2010-07-19 67 views
0

我正在使用以下tutorial將圖像文件上傳到網絡服務器。上傳文件到Web服務器時文件沒有找到異常?

並在此處獲取文件未找到異常。

try { 
     File uploadFile = new File(uriString); 

// file path i receive **content:/media/external/images/media/2** 

     FileInputStream fis = this.openFileInput(uploadFile.getName()); // **ERRoR HERE** 

     HttpFileUploader htfu = new HttpFileUploader("http://finditnear.sigmatec.com.pk/inbox/send_remote_reply","noparamshere", uploadFile.getName()); 
     htfu.doStart(fis); 
     } 
    catch (FileNotFoundException e) { 
     Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); 
     e.printStackTrace(); 
     return; 
     } 

圖像文件存在,但仍然給我錯誤。

任何人都可以指導我解決什麼問題嗎?

回答

2

內容:/ media/external/images/media/2文件名不正確,這是一個Uri。
所以這條線

FileInputStream fis = this.openFileInput(uploadFile.getName()); 

應與

InputStream fis=this.getContentResolver().openInputStream(new Uri(uriString)); 
+1

Uri構造函數不存在 反正謝謝是我得到了答案 InputStream fis = \t this.getContentResolver()。openInputStream(Uri.parse(uriString)); – UMAR 2010-07-20 06:56:39

+0

Ri ght,我沒有構建代碼,只是鍵入:-) – Fedor 2010-07-20 07:10:03

0

你加:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

AndroidManifest

+0

更換不,我沒有:( 和第二件事我只是想讀取圖像,並上傳,所以我可能需要讀許可權? 和 – UMAR 2010-07-19 16:18:58