ap-multipart

1.0.0 • Public • Published

Parse multipart formdata

This library simplifies parsing multipart form data in your Express applications. It extracts and provides you with structured information about the uploaded files, allowing you to implement your own file handling logic (e.g., saving to disk, uploading to cloud storage, etc.).

Key Features

  • Efficient Multipart Parsing: Efficiently parses multipart form data, simplifying the process of handling file uploads.

  • Detailed File Information: Provides structured file information for seamless processing:

    • filename: Original filename of the uploaded file.
    • extension: File extension (e.g., .jpg, .png).
    • mimetype: MIME content type of the file (e.g., image/jpeg, application/pdf).
    • size: File size in kilobytes (KB) for easy reference.
    • data: Buffer containing the raw file data for advanced handling.
  • Customizable File Handling: Leaves the file handling logic to your application, offering maximum flexibility for processing, storage, or further manipulation.

Installation

npm i ap-multipart

Usage

1. Middleware Integration:

const express = require("express");
const apMultiPart = require("ap-multipart");

const app = express();
app.use(express.json());
app.use(apMultiPart());

2. Access Uploaded Files:

app.post("/", async (req, res, next) => {
  const uploadedFiles = req.files;

  // Example: Accessing the first file
  const firstFile = uploadedFiles[0];
  const fileName = firstFile.filename;
  const fileData = firstFile.data;

  // ... Implement your file handling logic here ...

  res.json({ message: "Files received successfully!" });
});

3. Saving to Disk

const fs = require('fs');
const writable = await fs.createWriteStream(fileName);
writable.write(fileData);
writable.end();

Author

This library is maintained by Aman Pareek.

Feel free to connect, contribute, or reach out for collaborations!


MIT LICENSE

Readme

Keywords

Package Sidebar

Install

npm i ap-multipart

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.15 kB

Total Files

8

Last publish

Collaborators

  • amanpareek