initiallValue없으면? If initialValue is not specified, previousValue is initialized to the first value in the array, and currentValue is initialized to the second value in the array.
initialValue없고 대상array내 값이 1개뿐이라면?
뭘해도 [A] -> reduce(...) -> A 형태로 결과가 나옴, 즉 1개 있던 value가 array를 빠져나오게됨
@Description("MetaDataFile Download from Admin.")
@GetMapping
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping("/api/admin/apiCallLog/{apiCallLogId}/file")
public ResponseEntity<?> getMetaDataFile(@CurrentUser UserPrincipal currentUser,
@PathVariable Long apiCallLogId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
URL url = new URL(...어찌어찌해서 얻어옴);
InputStreamResource resource = new InputStreamResource(url.openStream());
resultMap.put("fileName", apiCallInfo.getFileName());
resultMap.put("resource", resource);
return ResponseEntity.ok().contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachement; filename=\"" + resultMap.get("fileName") + "\"")
.body(resultMap.get("resource"));
}
구현된 API call하는 부분
export async function getFileDownload(requestPath, requestMethod, rowData) {
await fetch(API_BASE_URL + requestPath, {
method: 'GET',
headers: getHeaders(),
})
.then(response => {
return response.blob();
})
.then(blob => {
const url = window.URL.createObjectURL(
new Blob([blob]),
);
const link = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
rowData.fileName,
);//filename to be downloaded, it can be used as link.download=fileName
//link.style='display:none'; //OK it is not given
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
})
.catch(err => {
alert('error')
});
}
BOM이란 문서 맨 앞에 눈에 보이지 않는 특정 바이트(byte)를 넣은 다음 이것을 해석해서 정확히 어떤 인코딩 방식이 사용되었는지 알아내는 방법을 나타냅니다. 자세하게 유니코드가 little-endian 인지 big-endian 인지 아니면 UTF-8 인지 쉽게 알 수 있도록, 유니코드 파일이 시작되는 첫부분에 보이지 않게, 2~3바이트의 문자열을 추가하는데 이것을 BOM이라고 합니다. BOM은 텍스트 에디터 화면에서는 보이지 않고, 헥사 에디터(Hex Editor)*로 열었을 때만 보입니다.
function extractBodyFieldKey(body, timeType, intl) {
let addUpDay = body.reduce( (acc, cur) => {
return acc.concat(cur);
});
addUpDay = sortByTimestamp(addUpDay);
return Papa.unparse(addUpDay.map(log => {
let eventTime = getTimeZoneTime(log, timeType);
let event = intl.formatMessage({id: util.eventLogMessageByCode(log.code)});
let userId = log.userKey;
let userName = log.userName;
let deviceDisplayName = log.deviceName;
return {eventTime, event, userId, userName, deviceDisplayName}
}))
}
[07-22 오전 11:30] 구본관: 저희 모카키도 그렇고 에어팝 포털도 그렇고 CSV 내보내기 할 때 대량으로 생성하게 되면 block 걸리는 경우가 발생합니다. 위에 이번에 변경된 UI도 파일작업을 할 때 동작을 멈추게 됩니다. addUpDay.map 이나 Papa.unparse 부분에서 시간이 굉장히 오래 걸리게 되는데 이때 렌더링이 멈추게 됩니다 대량으로 데이터를 처리할때는 비동기 방식으로 처리할 필요가 있습니다. 저희가 사용하는 papaparse 라이브러리를 보면 step 이나 chunk 같은 옵션들이 있습니다. 이번에 수정하려고 하는 것은 아니고 추후 개발에 참고하시면 좋겠습니다
-> 시간이 오래 걸려서 렌더링 멈춤? 상관없고 대량 데이터를 array로 한번에 처리해서 outOfMemory날뿐, 잘라서 처리해주면됨