update attachment & post
This commit is contained in:
@@ -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) => () => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user