웹뷰를 이용해서 이미지 첨부하는 기능을 만들었습니다.
웹뷰에서 input필드를 이용해서 도큐먼트를 호출 후 이미지를 선택해서 서버에 업로드 하는방식입니다.
킷캣 버전때문에 직접 구현했습니다.
그런데 문제는 내장메모리에서 읽고 쓰기는 잘 되는데 외장 메모리에선 읽지를 못합니다.
물론 권한은 읽고 쓰기 모두 주었습니다.
제가 대충 파악한 바로는 외장메모리에서 이미지 파일을 선택하면 그 경로를 못 읽어 오는듯 합니다.
외장메모리에서 이미지를 선택할때 특별히 처리해 주어야 되는게 있을까요?
현재 테스트중인 버전은 마쉬멜로우입니다.
이미지를 선택해서 서버로 전송하는 코드입니다.
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == GET_CAMERA_REQUEST) {
selectedImagePath = outputFile.getAbsolutePath();
if (outputFile.exists()) {
try {
viewProgressDialog();
client = new OkHttpClient();
post(IMAGE_UPLOAD_URL);
} catch (Exception e) {
e.printStackTrace();
}
}
}
else if (requestCode == GET_GALLERY_REQUEST) {
if (data != null) {
Uri selectedImageUri = data.getData();
selectedImagePath = RealPathUtil.getRealPath(this, selectedImageUri);
// 외장메모리의 경우에 여기서 selectedImagePath를 가져오지 못합니다.
try {
viewProgressDialog();
client = new OkHttpClient();
post(IMAGE_UPLOAD_URL);
} catch (Exception e) {
e.printStackTrace();
}
}
}
outputFile = null;
selectedImagePath = null;
}
RealPathUtil 클래스는 아래 경로의 소스를 사용했습니다.
http://stackoverflow.com/questions/28229518/getting-image-from-gallery-in-android/28229595#28229595