2013-07-17 15 views
1

我試圖通過POST HTTP方法將記錄的視頻文件保存在Android中的/storage/emulated/0/Videos/someVideo.3gp到遠程服務器上。我使用this作爲以FileBody格式將視頻文件傳遞到遠程服務器的一種方式。但是,最後當我試圖執行httpClient.execute(request)命令時,它只是繼續投擲FileNotFoundExceptionFileNotFoundException當訪問存儲在/ storage/emulated/0目錄中的文件android

所以,我不明白爲什麼視頻文件不能被外界訪問,因爲我已經使用getExternalStorageDirectory()將它保存到SD卡。我還爲清單文件添加了寫入權限。

P.S.我正在使用Nexus 7進行測試。請幫忙..

在此先感謝!

回答

1

您是否在執行httpClient.execute(request)之前檢查文件的存在?

從問題中引用你是以下幾點:

File sourceFile = new File(sourceFileUri); 
if (!sourceFile.isFile()) { 
Log.e("Huzza", "Source File Does not exist"); 
return 0; 
} 

編輯:
可能是你沒有從URI變換路徑上正確onActivityResult(...) method 我共享代碼獲取正確的路徑和它在我的應用程序中很好地工作。

String videoPath = ""; 
try 
{ 
String[] filePathColumn = { MediaStore.Video.Media.DATA }; 
Cursor cursor = getContentResolver().query(selectedVideoUri, 
filePathColumn, null, null, null); 
cursor.moveToFirst(); 
int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
videoPath = cursor.getString(columnIndex); 
cursor.close(); 
} catch (Exception e) { 
Log.e(TAG, 
"Error parsing Video path = " + e.toString()); 
} 
+1

我添加了現在檢查..並且,該文件不存在。但是,我不知道錯誤的原因。由於我在錄像完成後得到意圖返回的filePath .. –

+0

請檢查更新的答案。 –

+1

感謝您在我的實施中指出了這個問題。之前我實際上是試圖將記錄的視頻保存在SD卡中的自定​​義文件夾中,因此它不起作用。但是,當我嘗試你的代碼,並將其保存到它的默認位置,它的工作..!謝謝.. –

相關問題