-
Notifications
You must be signed in to change notification settings - Fork 662
Open
Description
This will allow the downloaded file to have the name of the file instead of a random string
--- a/vendor/jsr.io/@std/http/0.224.5/file_server.ts
+++ b/vendor/jsr.io/@std/http/0.224.5/file_server.ts
@@ -38,6 +38,7 @@ import { join } from "jsr:/@std/path@1.0.0-rc.2/join";
import { relative } from "jsr:/@std/path@1.0.0-rc.2/relative";
import { resolve } from "jsr:/@std/path@1.0.0-rc.2/resolve";
import { SEPARATOR_PATTERN } from "jsr:/@std/path@1.0.0-rc.2/constants";
+import { basename } from "jsr:/@std/path@1.0.0-rc.2/basename";
import { contentType } from "jsr:/@std/media-types@^1.0.0-rc.1/content-type";
import { calculate, ifNoneMatch } from "./etag.ts";
import {
@@ -232,6 +233,14 @@ export async function serveFile(
headers.set("content-type", contentTypeValue);
}
+ // Suggest original filename for downloads
+ const filename = basename(filePath);
+ const encodedFilename = encodeURIComponent(filename);
+ headers.set(
+ "content-disposition",
+ `attachment; filename*=UTF-8''${encodedFilename}`,
+ );
+
const fileSize = fileInfo.size;
const rangeValue = req.headers.get("range");Metadata
Metadata
Assignees
Labels
No labels