How to convert a file to Base64?

后端 未结 7 1400
遥遥无期
遥遥无期 2020-12-06 09:58

Here the report contain the path(pathname in sdcard in string format)

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, rep         


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 10:32

        public static String uriToBase64(Uri uri, ContentResolver resolver, boolean thumbnail) {
            String encodedBase64 = "";
            try {
                byte[] bytes = readBytes(uri, resolver, thumbnail);
                encodedBase64 = Base64.encodeToString(bytes, 0);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return encodedBase64;
        }

    and call it in this way

       String image = BitmapUtils.uriToBase64(Uri.fromFile(file), context.getContentResolver());

提交回复
热议问题