@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')
});
}
<input> width:0으로 해도 변화가 없음 -> <input>의 기본 display:inline이라서 그런줄 알았으나 display:block이었음 -> input의 부모가 display:flex이고 선택된 tab들을 flex형태로 보여주는 데 이 경우 뭔가 제약이 있는 것 같음