Skip to content

Commit

Permalink
Update mod.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
hviana committed Jun 4, 2020
1 parent 5e1c238 commit 8c17b2e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mod.ts
Expand Up @@ -6,6 +6,7 @@ const upload = function (
maxSizeBytes: number = Number.MAX_SAFE_INTEGER,
maxFileSizeBytes: number = Number.MAX_SAFE_INTEGER,
saveFile: boolean = true,
readFile: boolean = false,
useCurrentDir: boolean = true,
) {
return async (context: any, next: any) => {
Expand Down Expand Up @@ -66,6 +67,9 @@ const upload = function (
for (const fileData of filesData) {
if (fileData.tempfile !== undefined) {
let resData = fileData;
if (readFile) {
resData["data"] = await Deno.readFile(resData["tempfile"]);
}
if (saveFile) {
const d = new Date();
const uuid = `${d.getFullYear()}/${d.getMonth() +
Expand All @@ -86,9 +90,6 @@ const upload = function (
`${uploadPath}/${fileData.filename}`,
);
resData["uri"] = `${fullPath}/${fileData.filename}`;
} else {
resData["data"] = await Deno.readFile(resData["tempfile"]);
delete resData["tempfile"];
}
if (res[formField] !== undefined) {
if (Array.isArray(res[formField])) {
Expand Down

0 comments on commit 8c17b2e

Please sign in to comment.