fix: resolve file download error
- content-type이 text/html 일 경우에만 에러 핸들링, 이외 타입은 octet-stream으로 반환
This commit is contained in:
parent
8c36446de7
commit
7f14135616
@ -4,6 +4,7 @@ import { NextResponse } from 'next/server'
|
|||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const { searchParams } = new URL(request.url)
|
const { searchParams } = new URL(request.url)
|
||||||
const encodeFileNo = searchParams.get('encodeFileNo')
|
const encodeFileNo = searchParams.get('encodeFileNo')
|
||||||
|
|
||||||
const srcFileNm = searchParams.get('srcFileNm')
|
const srcFileNm = searchParams.get('srcFileNm')
|
||||||
|
|
||||||
if (!encodeFileNo) {
|
if (!encodeFileNo) {
|
||||||
@ -16,17 +17,16 @@ export async function GET(request: Request) {
|
|||||||
encodeFileNo,
|
encodeFileNo,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (response.headers['content-type'] === 'application/octet-stream;charset=UTF-8') {
|
if (response.headers['content-type'] === 'text/html;charset=utf-8') {
|
||||||
return new NextResponse(response.data, {
|
|
||||||
status: 200,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/octet-stream;charset=UTF-8',
|
|
||||||
'Content-Disposition': `attachment; filename="${srcFileNm}"`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return NextResponse.json({ error: 'file not found' }, { status: 404 })
|
return NextResponse.json({ error: 'file not found' }, { status: 404 })
|
||||||
}
|
}
|
||||||
|
return new NextResponse(response.data, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/octet-stream;charset=UTF-8',
|
||||||
|
'Content-Disposition': `attachment; filename="${srcFileNm}"`,
|
||||||
|
},
|
||||||
|
})
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return NextResponse.json({ error: error.response.data }, { status: 500 })
|
return NextResponse.json({ error: error.response.data }, { status: 500 })
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user