@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();
}