내 문제가 이미 여러 번 해결되었지만 특정 문제를 해결하는 데 도움이되는 내용을 찾을 수 없습니다.async-http 파일 업로드 파일 (파일 경로에 대한 uri)을 가져 오는 파일
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
내가 여기이 의도 픽업 :
나는 시스템에서 아무 곳이나 파일을 선택하는 의도가
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
}
을 내가 업로드 방법 등이있다 그래서 :
private void upload(File file){
RequestParams params = new RequestParams();
try {
params.put("fileToUpload", file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post("http://...", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println("statusCode "+statusCode);//statusCode 200
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
}
문제는 AsyncHttpClient에서 사용할 수 있도록 의도에서 얻은 정보를 처리하는 방법을 모르므로 onActivity 및 업로드의 두 메서드를 "결혼"하는 방법을 모르겠다는 것입니다.
저는 Uri를 절대 경로로 변환하려고 시도했지만 관리 할 수 없었습니다 (이미지를 위해 특별히 작동하는 것처럼 보이는 솔루션). 또한 uri를 파일로 "변환"할 수도 없습니다.
어쨌든 이것을 할 수 있습니까? 내가 놓친 게 있니?
예, 감사합니다. Async-Http는 파일 대신 입력 스트림을 허용합니다. – hachel