0

I want to get pdf and convert it into base64. use this code to start picker

Intent  intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            String [] mimeTypes = {"image/*", "application/pdf"};
            intent.setType("*/*");
            intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
            startActivityForResult(intent, 1);

I had used below solution : https://stackoverflow.com/a/41440869/6864437

but it is not working on android pie

getting below error: Request header queries do not support projections, selections or sorting

How to get the Full file path from URI

  • 1
    Why would you need a a File path? You can do all using the obtained url directly. – blackapps Oct 24 '19 at 15:56
  • For the rest you should post the relevant code. – blackapps Oct 24 '19 at 15:57
  • String base64 = ""; try { byte[] buffer = new byte[(int) file.length() + 100]; @SuppressWarnings("resource") int length = new FileInputStream(file).read(buffer); base64 = Base64.encodeToString(buffer, 0, length, Base64.DEFAULT); } catch (IOException e) { e.printStackTrace(); } return base64; use this code to create base 64 and file name is also required to store it in server @blackapps – Dhiraj Gurunule Oct 24 '19 at 16:33
  • 1
    Instead of the FileInputSTream you could use an InputStream directly for the obtained uri: `InputSTream is =getContentResolver().openInputStream(data.getData());`. The rest of the code is the same. – blackapps Oct 24 '19 at 16:47
  • @blackapps Also need to retrieve file name and extension – Dhiraj Gurunule Oct 25 '19 at 04:01
  • You can get the DISPLAY_NAME with querying the contentresolver with the obtained uri. – blackapps Oct 25 '19 at 07:38

1 Answers1

1

Solution used : I use input stream (suggested by @blackaaps) to get data from file and create new file which I can use to get full path.