Member 10637123 Ответов: 0

Загрузка pdf-файла без преобразования в base64 в android


private String KEY_IMAGE = "image";
            private String KEY_NAME = "name";

            private int PICK_IMAGE_REQUEST = 1;
            VolleyAppController volleyAppController;
            mydb db;
            public static String url = "http://xxx.xxx.x.x:xx/Android_Service.asmx/UploadPDFFile";
            int SELECT_MAGAZINE_FILE = 1;
            private File myFile;
            String encodeFileToBase64Binary = "";

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                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);
                    oos.writeObject(file);
                    bos.close();
                    oos.close();
                    byte[] bytearray = bos.toByteArray();
                    encoded = Base64.encodeToString(bytearray, Base64.DEFAULT);
                } catch (Exception ex) {

                }
                return encoded;
            }


            private void uploadImage() {


                    @RequiresApi(api = Build.VERSION_CODES.O)
                    @Override
                    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;
                    }
                };

        }     


Что я уже пробовал:

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

"Я не могу конвертировать pdf-файл в строку base64..."

Используя отладчик, вы прошли через код, чтобы выяснить, почему?

0 Ответов