update attachment & post

This commit is contained in:
jooho
2021-11-02 17:15:27 +09:00
parent 06975932b6
commit c50df972e9
13 changed files with 229 additions and 90 deletions

View File

@@ -35,10 +35,7 @@ const AttachList = (props: AttachListProps) => {
const classes = useStyles()
const handleClick = (item: IAttachmentResponse) => () => {
let a = document.createElement('a')
a.href = `${fileService.downloadUrl}/${item.id}`
a.download = item.originalFileName
a.click()
fileService.download(item.id)
}
const handleDelete = (item: IAttachmentResponse) => () => {

View File

@@ -100,6 +100,10 @@ const getColumns: ColumnType = (
href={`${fileService.downloadUrl}/${params.row.id}`}
download={params.value}
variant="body2"
onClick={(event) => {
event.preventDefault()
attachmentService.download(params.row.id)
}}
>
{params.value}
</Link>

View File

@@ -55,4 +55,22 @@ export const attachmentService = {
errorCallback(error)
}
},
download: (id: string) => { // 첨부파일 다운로드 - 삭제 파일 가능
axios.get(`${ATTACHMENT_API}/download/${id}`, {
responseType: 'blob',
})
.then(response =>{
const downloadFileName = decodeURIComponent(response.headers['content-disposition'].replace('attachment; filename*=UTF-8\'\'', ''))
const url = window.URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] }))
let link = document.createElement('a')
link.href = url
link.setAttribute('download', downloadFileName)
document.body.appendChild(link)
link.click()
const element = { link }
delete element.link
})
},
}

View File

@@ -38,7 +38,7 @@ export type UploadPayload = {
}
const UPLOAD_API = '/portal-service/api/v1/attachments'
const DOWNLOAD_API = `/server/portal-service/api/v1/download`
const DOWNLOAD_API = `/portal-service/api/v1/download`
let fileHeader = {
'Content-Type': 'multipart/form-data',
@@ -105,4 +105,22 @@ export const fileService = {
},
deleteAll: (attachmentCode: string) =>
axios.delete(`${UPLOAD_API}/${attachmentCode}/children`),
download: (id: string) => { // 첨부파일 다운로드 - 삭제 파일 불가
axios.get(`${DOWNLOAD_API}/${id}`, {
responseType: 'blob',
})
.then(response =>{
const downloadFileName = decodeURIComponent(response.headers['content-disposition'].replace('attachment; filename*=UTF-8\'\'', ''))
const url = window.URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] }))
let link = document.createElement('a')
link.href = url
link.setAttribute('download', downloadFileName)
document.body.appendChild(link)
link.click()
const element = { link }
delete element.link
})
},
}