Skip to content

Commit

Permalink
Improve file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Sep 8, 2024
1 parent 89819ce commit a48381b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions _payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,16 @@ async function resolveFilesFormData(workspace: string, files: string[]): Promise
for (let index = 0; index < files.length; index += 1) {
const file: string = files[index];
const fileBasename: string = pathBasename(file);
attachments.push({
const fileContentType: string | undefined = contentType(pathExtname(file));
const attachment: JSONObject = {
filename: fileBasename,
id: index
});
formData.append(`files[${index}]`, new Blob([await Deno.readFile(pathJoin(workspace, file))], { type: contentType(pathExtname(file)) }), fileBasename);
};
if (typeof fileContentType !== "undefined") {
attachment.content_type = fileContentType;
}
attachments.push(attachment);
formData.append(`files[${index}]`, new Blob([await Deno.readFile(pathJoin(workspace, file))], { type: fileContentType }), fileBasename);
}
formData.append("attachments", JSON.stringify(attachments));
return formData;
Expand Down

0 comments on commit a48381b

Please sign in to comment.