Java上傳ZIP解壓獲取圖片流

@RequestMapping("/batchUploadImage")
    public RestResult<ImportVO> batchUploadImage(@RequestParam("file") MultipartFile zipFile, CommunityCodeParam param) {
        if (zipFile == null) {
            return RestResult.wrapErrorResponse("請上傳壓縮包");
        }
        //設置格式 防止壓縮包中文亂碼
        try (ZipInputStream zin = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"))) {
            ZipEntry entry;
            while ((entry = zin.getNextEntry()) != null) {
                if (!entry.isDirectory()) {
                    String entryName = entry.getName();
                    if (entryName != null) {
                        String[] url = entryName.split("\\.");
                        String[] split = url[0].split("/");
                        String nameAndPhone = split[split.length - 1];
                        String[] splitName = nameAndPhone.split("-");
                        String name = splitName[0];
                        String phone = splitName[1];
                    }
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    byte[] array = new byte[1024];
                    int num = -1;
                    while ((num = zin.read(array, 0, array.length)) > -1) {
                        byteArrayOutputStream.write(array, 0, num);
                    }
                    byte[] bytes = byteArrayOutputStream.toByteArray();
                    String imageUrl = ossUtil.uploadToOss(bytes, entryName, OssUtil.FACE_SIZE_DEFAULT);
                    System.out.println(imageUrl);
                }
                zin.closeEntry();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章