Skip to content

Commit

Permalink
Fix file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Sep 6, 2024
1 parent b3b9fad commit d8ef19a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions _payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
type JSONValue,
} from "ISJSON";
import getRegExpURL from "REGEXPURL";
import { contentType } from "STD/media-types/content-type";
import { basename as pathBasename } from "STD/path/basename";
import { extname as pathExtname } from "STD/path/extname";
import { isAbsolute as pathIsAbsolute } from "STD/path/is-absolute";
import { globToRegExp } from "STD/path/glob-to-regexp";
import { join as pathJoin } from "STD/path/join";
Expand Down Expand Up @@ -349,12 +351,13 @@ async function resolveFilesFormData(files: string[]): Promise<FormData> {
const formData: FormData = new FormData();
const attachments: JSONObject[] = [];
for (let index = 0; index < files.length; index += 1) {
const fileBasename: string = pathBasename(files[index]);
const file: string = files[index];
const fileBasename: string = pathBasename(file);
attachments.push({
filename: fileBasename,
id: index
});
formData.append(`files[${index}]`, new Blob([await Deno.readFile(files[index])]), fileBasename);
formData.append(`files[${index}]`, new Blob([await Deno.readFile(file)], { type: contentType(pathExtname(file)) }), fileBasename);
}
formData.append("attachments", JSON.stringify(attachments));
return formData;
Expand Down
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"REGEXPURL": "https://esm.sh/url-regex-safe@^4.0.0",
"STD/assert": "jsr:@std/assert@^1.0.4",
"STD/fs": "jsr:@std/fs@^1.0.3",
"STD/media-types": "jsr:@std/media-types@^1.0.3",
"STD/path": "jsr:@std/path@^1.0.4",
"STD/yaml": "jsr:@std/yaml@^1.0.5",
"STRINGOVERFLOW": "jsr:@hugoalh/string-overflow@^2.0.3"
Expand Down

0 comments on commit d8ef19a

Please sign in to comment.