fix: download url 변경
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
import { Page } from '@utils'
|
||||||
import axios, { AxiosError } from 'axios'
|
import axios, { AxiosError } from 'axios'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { common, SearchPayload } from './common'
|
import { common, SearchPayload } from './common'
|
||||||
import { Page } from '@utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* request payload
|
* request payload
|
||||||
@@ -55,14 +55,23 @@ export const attachmentService = {
|
|||||||
errorCallback(error)
|
errorCallback(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
download: (id: string) => { // 첨부파일 다운로드 - 삭제 파일 가능
|
download: (id: string) => {
|
||||||
axios.get(`${ATTACHMENT_API}/download/${id}`, {
|
// 첨부파일 다운로드 - 삭제 파일 가능
|
||||||
|
axios
|
||||||
|
.get(`/portal-service/api/v1/download/${id}`, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
})
|
})
|
||||||
.then(response =>{
|
.then(response => {
|
||||||
const downloadFileName = decodeURIComponent(response.headers['content-disposition'].replace('attachment; filename*=UTF-8\'\'', ''))
|
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'] }))
|
const url = window.URL.createObjectURL(
|
||||||
|
new Blob([response.data], { type: response.headers['content-type'] }),
|
||||||
|
)
|
||||||
let link = document.createElement('a')
|
let link = document.createElement('a')
|
||||||
link.href = url
|
link.href = url
|
||||||
link.setAttribute('download', downloadFileName)
|
link.setAttribute('download', downloadFileName)
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ function Logout() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
export const getServerSideProps: GetServerSideProps = async ({
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
query,
|
||||||
|
}) => {
|
||||||
|
console.log(query)
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
const Cookies = require('cookies')
|
const Cookies = require('cookies')
|
||||||
const cookies = new Cookies(req, res)
|
const cookies = new Cookies(req, res)
|
||||||
@@ -26,12 +31,17 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
|||||||
axios.defaults.headers.common[CLAIM_NAME] = ''
|
axios.defaults.headers.common[CLAIM_NAME] = ''
|
||||||
axios.defaults.headers.common[AUTH_USER_ID] = ''
|
axios.defaults.headers.common[AUTH_USER_ID] = ''
|
||||||
|
|
||||||
|
try {
|
||||||
const { redirect } = req['query']
|
const { redirect } = req['query']
|
||||||
|
|
||||||
res.writeHead(307, {
|
res.writeHead(307, {
|
||||||
Location: typeof redirect !== 'undefined' ? redirect : '/',
|
Location: typeof redirect !== 'undefined' ? redirect : '/',
|
||||||
})
|
})
|
||||||
res.end()
|
res.end()
|
||||||
|
} catch (error) {
|
||||||
|
res.writeHead(307, { Location: '/' })
|
||||||
|
res.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user