OPEN between Secret

android studio 에서 multipart를 이용한 이미지 서버로 전송하기 본문

T.N.V/응용1

android studio 에서 multipart를 이용한 이미지 서버로 전송하기

해가꿈꾸는달 2018. 5. 3. 12:03
반응형

http://www.pratikbutani.com/2016/06/android-upload-image-file-using-retrofit-2-0/

https://androidclarified.com/android-image-upload-example/


참고로 갤러리에서 갖고온 이미지 경로는 context:?? 로 시작하는데 이 경로에 있는 이미지를 서버로 보내려고 하면 error 발생

이미지의 절대경로를 갖고와서 보내야 하늗네 그 절대경로는 다음 소스를 통해서 구할수 있음

private String getRealPathFromURI(Uri contentURI) {
        String filePath;
        Cursor cursor = getActivity().getContentResolver().query(contentURI, null, null, null, null);
        if (cursor == null) { 
            filePath = contentURI.getPath();
        } else {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
            filePath = cursor.getString(idx);
            cursor.close();
        }
        return filePath;
    }


반응형