Next js 14 Router Handler download file fail ,i try many methods ,but they all not work for me. #62488
Unanswered
imtiger
asked this question in
App Router
Replies: 1 comment
-
hi guys ,i have solved this problem . just because the file name contains the chinese words. i encodeURIComponent the filename ,it works. thank god!
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`export async function GET(
request: NextRequest
) {
const filePath = "...."
let buffer = fs.readFileSync(filePath);
}`
above code not work
it throw an error below:
TypeError: Cannot convert argument to a ByteString because the character at index 22 has a value of 25163 which is greater than 255.
at webidl.converters.ByteString (node:internal/deps/undici/undici:1629:17)
at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1538:32)
at webidl.converters.HeadersInit (node:internal/deps/undici/undici:2030:67)
at Object.ResponseInit (node:internal/deps/undici/undici:1594:21)
at new Response (node:internal/deps/undici/undici:6767:34)
at GET (webpack-internal:///(rsc)/./app/(transfer)/download/route.ts:32:28)
my package.json file below:
`
{
"name": "djb",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"build:dev": "ENVIRONMENT=.env.development next build",
"start": "next start",
"lint": "next lint",
"p:g": "dotenv -e .env.development npx prisma generate",
"p:dp": "dotenv -e .env.development npx prisma db push",
"p:s": "dotenv -e .env.development npx prisma studio",
"p:f": "dotenv -e .env.development npx prisma format"
},
"dependencies": {
"@emotion/react": "^11.10.6",
"@fullcalendar/core": "^6.1.4",
"@fullcalendar/daygrid": "^6.1.4",
"@fullcalendar/interaction": "^6.1.1",
"@fullcalendar/react": "^6.1.4",
"@fullcalendar/timegrid": "^6.1.1",
"@headlessui/react": "^1.7.8",
"@mantine/core": "^7.5.1",
"@mantine/hooks": "^7.5.1",
"@prisma/client": "^5.8.1",
"@reduxjs/toolkit": "^1.9.1",
"@tippyjs/react": "^4.2.6",
"@types/node": "18.11.18",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"@x1mrdonut1x/nouislider-react": "^3.4.3",
"apexcharts": "^3.37.1",
"axios": "^1.6.7",
"clsx": "^2.1.0",
"D": "^1.0.0",
"dayjs": "^1.11.10",
"dotenv": "^16.4.3",
"easymde": "^2.18.0",
"eslint": "8.32.0",
"eslint-config-next": "13.1.2",
"exceljs": "^4.4.0",
"flatpickr": "^4.6.13",
"formik": "^2.4.5",
"highlight.js": "^11.7.0",
"i18next": "^22.4.10",
"lodash": "^4.17.21",
"mantine-datatable": "^7.5.0",
"next": "^14.1.0",
"next-auth": "^5.0.0-beta.5",
"ni18n": "^1.0.5",
"pino-pretty": "^10.3.1",
"react": "18.2.0",
"react-animate-height": "^3.1.0",
"react-apexcharts": "^1.4.0",
"react-click-away-listener": "^2.2.2",
"react-copy-to-clipboard": "^5.1.0",
"react-countup": "^6.4.1",
"react-dom": "18.2.0",
"react-flatpickr": "^3.10.13",
"react-i18next": "^12.1.5",
"react-images-uploading": "^3.1.7",
"react-perfect-scrollbar": "^1.5.8",
"react-popper": "^2.3.0",
"react-quill": "^2.0.0",
"react-redux": "^8.1.3",
"react-select": "^5.7.0",
"react-simplemde-editor": "^5.2.0",
"react-sortablejs": "^6.1.4",
"react-text-mask": "^5.5.0",
"redis": "^4.6.12",
"sortablejs": "^1.15.0",
"sweetalert2": "^11.7.1",
"sweetalert2-react-content": "^5.0.7",
"swiper": "^8.4.7",
"typescript": "^5.3.3",
"universal-cookie": "^6.1.1",
"use-debounce": "^10.0.0",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^5.0.0",
"yet-another-react-lightbox": "^3.15.6",
"yup": "^0.32.11",
"zod": "^3.22.4"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.8",
"@types/lodash": "^4.14.191",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-flatpickr": "^3.8.8",
"@types/react-redux": "^7.1.32",
"@types/react-text-mask": "^5.4.11",
"@types/sortablejs": "^1.15.0",
"autoprefixer": "^10.4.13",
"cross-env": "^7.0.3",
"postcss": "^8.4.21",
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.2.0",
"prisma": "^5.8.1",
"prisma-next-crud-generator": "^1.3.0",
"tailwindcss": "^3.3.2",
"ts-node": "^10.9.2"
}
}
`
At first, I thought the error was caused by having Chinese characters in the downloaded Excel file. However, later I emptied the file and left it as an empty XLSX file, but I still received the same error.
anyone know how to make it work,thanks.
Beta Was this translation helpful? Give feedback.
All reactions