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.).
-
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.
npm i ap-multipart
const express = require("express");
const apMultiPart = require("ap-multipart");
const app = express();
app.use(express.json());
app.use(apMultiPart());
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!" });
});
const fs = require('fs');
const writable = await fs.createWriteStream(fileName);
writable.write(fileData);
writable.end();
This library is maintained by Aman Pareek.
- GitHub: https://github.com/amanp30
- LinkedIn: https://www.linkedin.com/in/aman-pareek
Feel free to connect, contribute, or reach out for collaborations!