Загрузить файл на сервер с помощью JUNIT - PullRequest
0 голосов
/ 29 мая 2020
    @Test
    void test() {
        try {

            String filePath = "C:/Users/Administrator/Desktop/backupv2/imageMgmt/asdf/";
            File directory = new File(filePath);
            if (!directory.exists()) {
                Files.createDirectories(Paths.get(filePath));
                directory.mkdir();
            }
            String val = "space";
            File imageValue = new File("C:/Users/Administrator/Desktop/backupv2/" + val + ".gif");
            FileInputStream imageInFile = new FileInputStream(imageValue);

            byte[] imageByte= new byte[(int) (imageValue.length())];
            imageInFile.read(imageByte);
            String base64String = Base64.getEncoder().encodeToString(imageByte);

            //Path destinationFile = Paths.get("https://172.20.188.63:8553/m/" + val + ".gif");
            Path destinationFile = Paths.get(filePath + val + ".gif");

            byte[] decoded = Base64.getDecoder().decode(base64String);
            System.out.println("Path: " + destinationFile.toString());

            Files.write(destinationFile, decoded);

            System.out.println("Upload success!");

        }catch(Exception e) {

        }
    }

Можно ли в JUNIT загрузить файл на сервер по URL-адресу? Локально я могу загрузить образец изображения в другой каталог, но не напрямую на сервер.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...