Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private String KEY_IMAGE = "image";
            private String KEY_NAME = "name";

            private int PICK_IMAGE_REQUEST = 1;
            VolleyAppController volleyAppController;
            mydb db;
            public static String url = "";
            int SELECT_MAGAZINE_FILE = 1;
            private File myFile;
            String encodeFileToBase64Binary = "";

            protected void onCreate(Bundle savedInstanceState) {
                db = new mydb(this);
                volleyAppController = new VolleyAppController();

            private String NewBase64(String Path) {

                String encoded = "";
                try {
                    File file = new File(Path);

                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    ObjectOutputStream oos = new ObjectOutputStream(bos);
                    oos = new ObjectOutputStream(bos);
                    byte[] bytearray = bos.toByteArray();
                    encoded = Base64.encodeToString(bytearray, Base64.DEFAULT);
                } catch (Exception ex) {

                return encoded;

            private void uploadImage() {

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    protected Map<String, String> getParams() throws AuthFailureError {

                        String image = null;

                        image = NewBase64(encodeFileToBase64Binary);

                        String name1 = name.getText().toString().trim();

                        Map<String, String> params = new Hashtable<String, String>();

                        params.put(KEY_IMAGE, image);
                        params.put(KEY_NAME, name1);

                        return params;


What I have tried:

I'm not able to convert pdf file to base64 string but file uploaded successfully when I open pdf file it showing 0kb file size. This same code works for an image but when I try to use to convert for pdf file it is not working. in my code I have created a method called 'NewBase64' in that I'm converting pdf file to base64 can any tell me where I'm gone wrong.
David Crow 16-Apr-19 9:52am    
"I'm not able to convert pdf file to base64 string..."

Using the debugger, have you stepped through the code to find out why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900