Skip to main content

Upload File

NHttp built in multipart by default. so NO need any library to handle upload.

Support only Deno runtime.

import { NHttp, multipart } from "https://deno.land/x/nhttp@1.1.11/mod.ts";const app = new NHttp();
// handle upload multipart/form-dataapp.post("/upload", multipart.upload({ name: "image" }), ({ response, file }) => {    console.log(file.image);    // => file or [file1, file2]    return response.send('success upload file');});app.listen(3000);

Multipart#

Cause based on native HTTP, handling multipart is very simple.

...
// uploadmultipart.upload({ name: "image" });
// single uploadmultipart.upload({ name: "image", maxCount: 1 });
// required field (will throw bad request error 400)multipart.upload({ name: "image", required: true });
// accept filemultipart.upload({ name: "image", accept: 'png|jpg' });
// maxSize filemultipart.upload({ name: "image", maxSize: '2 mb' });
// callbackmultipart.upload({    name: "image",     callback: (file) => {        // change filename        file.filename = Date.now() + file.name;    }});
// destinationmultipart.upload({    name: "image",     dest: "public/user_folder/"});
// multiple fieldmultipart.upload(    [        {             name: "user_image",             dest: "public/user_folder/"            // other        },        {             name: "employee_image",             dest: "public/employee_folder/"            // other        }    ]);...