fix(api): correct values of Content-Disposition attributes (#260)
This commit is contained in:
@@ -17,12 +17,11 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const downloadUrl = decodeURIComponent(url);
|
const downloadFilename = typeof filename === "string"
|
||||||
const downloadFilename =
|
? encodeURIComponent(filename)
|
||||||
(typeof filename === "string" ? decodeURIComponent(filename) : null) ??
|
: "attachment";
|
||||||
"attachment";
|
|
||||||
|
|
||||||
const upstream = await fetch(downloadUrl);
|
const upstream = await fetch(url);
|
||||||
|
|
||||||
if (!upstream.ok) {
|
if (!upstream.ok) {
|
||||||
return res.status(upstream.status).json({
|
return res.status(upstream.status).json({
|
||||||
@@ -36,7 +35,7 @@ export default async function handler(
|
|||||||
res.setHeader("Content-Type", contentType);
|
res.setHeader("Content-Type", contentType);
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
"Content-Disposition",
|
"Content-Disposition",
|
||||||
`attachment; filename="${downloadFilename}"`,
|
`attachment; filename="${downloadFilename}"; filename*=UTF-8''${downloadFilename}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const buffer = await upstream.arrayBuffer();
|
const buffer = await upstream.arrayBuffer();
|
||||||
|
|||||||
Reference in New Issue
Block a user