파일 업로드 방식
- busboy:
busboy
는 스트리밍 방식으로 파일을 업로드합니다. 파일 데이터를 청크 단위로 처리하여 메모리 사용을 최소화하며, 대용량 파일 업로드에 적합합니다. - formidable:
formidable
은 스트리밍 방식으로 파일을 처리합니다. 파일 데이터를 청크 단위로 읽어들이며, 메모리 사용을 최소화합니다. 대용량 파일 업로드에 적합합니다. - multer:
multer
는 파일을 메모리 또는 디스크에 저장할 수 있습니다. 저장 방식을 설정할 수 있으며, 기본적으로 메모리에 저장합니다. 대용량 파일 처리 시 디스크 저장 방식을 사용하는 것이 좋습니다. - express-fileupload:
express-fileupload
는 파일을 메모리에 저장한 후, 지정된 경로로 이동시키는 방식입니다. 기본 설정에서는 파일을 메모리에 저장하므로, 대용량 파일 업로드 시 메모리 사용에 주의해야 합니다. - connect-multiparty:
connect-multiparty
는 파일과 텍스트 데이터를 동시에 처리합니다. 파일 데이터를 메모리에 저장한 후, 필요에 따라 디스크에 저장합니다. 이로 인해 메모리 사용량이 증가할 수 있습니다. - connect-busboy:
connect-busboy
는busboy
의 스트리밍 방식을 그대로 사용합니다. 따라서, 메모리 사용량이 적고, 대용량 파일 업로드에 적합합니다.
진행률 추적
- busboy:
busboy
는 파일 업로드 진행률을 추적할 수 있는 이벤트를 제공합니다.file
이벤트에서data
이벤트를 사용하여 진행률을 계산할 수 있습니다. - formidable:
formidable
은 파일 업로드 진행률을 추적할 수 있는 이벤트를 제공합니다.progress
이벤트를 사용하여 진행률을 실시간으로 모니터링할 수 있습니다. - multer:
multer
는 파일 업로드 진행률을 추적하는 기능을 제공하지 않습니다. 진행률을 추적하려면 추가적인 구현이 필요합니다. - express-fileupload:
express-fileupload
는 파일 업로드 진행률을 추적하는 기능을 기본적으로 제공하지 않습니다. 그러나, 클라이언트 측에서 진행률을 계산하여 표시할 수 있습니다. - connect-multiparty:
connect-multiparty
는 파일 업로드 진행률을 추적할 수 있는 기능을 제공합니다. 그러나, 진행률 이벤트를 수동으로 처리해야 합니다. - connect-busboy:
connect-busboy
는busboy
의 진행률 추적 기능을 그대로 제공합니다. 파일 업로드 진행률을 실시간으로 모니터링할 수 있습니다.
파일 크기 제한
- busboy:
busboy
는 파일 크기 제한을 설정할 수 있는 기능을 제공합니다.file
이벤트에서limit
옵션을 사용하여 최대 파일 크기를 지정할 수 있습니다. - formidable:
formidable
은 파일 크기 제한을 설정할 수 있습니다.maxFileSize
옵션을 사용하여 최대 파일 크기를 지정할 수 있으며, 이를 초과하는 파일은 업로드할 수 없습니다. - multer:
multer
는 파일 크기 제한을 설정할 수 있는 기능을 제공합니다.limits
옵션을 사용하여 최대 파일 크기를 지정할 수 있으며, 이를 초과하는 파일은 업로드할 수 없습니다. - express-fileupload:
express-fileupload
는 파일 크기 제한을 설정할 수 있는 기능을 제공합니다.limits
옵션을 사용하여 최대 파일 크기를 지정할 수 있으며, 이를 초과하는 파일은 업로드할 수 없습니다. - connect-multiparty:
connect-multiparty
는 파일 크기 제한을 설정할 수 있습니다.maxFileSize
옵션을 사용하여 최대 파일 크기를 지정할 수 있으며, 이를 초과하는 파일은 업로드할 수 없습니다. - connect-busboy:
connect-busboy
는busboy
의 파일 크기 제한 기능을 그대로 제공합니다. 최대 파일 크기를 설정하여, 지정된 크기를 초과하는 파일 업로드를 차단할 수 있습니다.
다중 파일 업로드
- busboy:
busboy
는 다중 파일 업로드를 지원합니다.file
이벤트를 사용하여 여러 파일을 순차적으로 처리할 수 있습니다. - formidable:
formidable
은 다중 파일 업로드를 지원합니다. 여러 파일을 동시에 업로드할 수 있으며, 각 파일에 대한 정보를 개별적으로 처리할 수 있습니다. - multer:
multer
는 다중 파일 업로드를 지원합니다.multiple
속성을 사용하여 여러 파일을 동시에 업로드할 수 있으며, 업로드된 파일은 배열 형태로 처리됩니다. - express-fileupload:
express-fileupload
는 다중 파일 업로드를 지원합니다.multiple
속성을 사용하여 여러 파일을 동시에 업로드할 수 있으며, 업로드된 파일은 배열 형태로 처리됩니다. - connect-multiparty:
connect-multiparty
는 다중 파일 업로드를 지원합니다. 여러 파일을 동시에 업로드할 수 있으며, 각 파일에 대한 정보를 개별적으로 처리할 수 있습니다. - connect-busboy:
connect-busboy
는busboy
의 다중 파일 업로드 기능을 그대로 제공합니다. 여러 파일을 동시에 업로드할 수 있으며, 각 파일에 대한 이벤트를 개별적으로 처리할 수 있습니다.
Ease of Use: Code Examples
- busboy:
busboy
를 사용한 파일 업로드 예제const http = require('http'); const Busboy = require('busboy'); http.createServer((req, res) => { if (req.method === 'POST') { const busboy = new Busboy({ headers: req.headers }); busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { console.log(`파일 이름: ${filename}`); file.on('data', (data) => { console.log(`파일 데이터: ${data.length} 바이트`); }); file.on('end', () => { console.log('파일 업로드 완료'); }); }); busboy.on('finish', () => { res.writeHead(200, { '결과': '파일 업로드 성공' }); res.end(); }); req.pipe(busboy); } else { res.writeHead(405, { 'Content-Type': 'text/plain' }); res.end('허용되지 않는 메서드'); } }).listen(3000); console.log('서버가 3000번 포트에서 실행 중');
- formidable:
formidable
을 사용한 파일 업로드 예제const http = require('http'); const formidable = require('formidable'); http.createServer((req, res) => { if (req.method === 'POST') { const form = new formidable.IncomingForm(); form.parse(req, (err, fields, files) => { if (err) { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('파일 업로드 실패'); return; } console.log('업로드된 파일:', files); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('파일 업로드 성공'); }); } else { res.writeHead(405, { 'Content-Type': 'text/plain' }); res.end('허용되지 않는 메서드'); } }).listen(3000); console.log('서버가 3000번 포트에서 실행 중');
- multer:
multer
를 사용한 파일 업로드 예제const express = require('express'); const multer = require('multer'); const app = express(); const upload = multer({ dest: 'uploads/' }); app.post('/upload', upload.single('file'), (req, res) => { console.log(`파일 이름: ${req.file.originalname}`); console.log(`파일 경로: ${req.file.path}`); res.send('파일 업로드 성공'); }); app.listen(3000, () => { console.log('서버가 3000번 포트에서 실행 중'); });
- express-fileupload:
express-fileupload
를 사용한 파일 업로드 예제const express = require('express'); const fileUpload = require('express-fileupload'); const app = express(); app.use(fileUpload()); app.post('/upload', (req, res) => { const file = req.files.file; console.log(`파일 이름: ${file.name}`); console.log(`파일 크기: ${file.size} 바이트`); res.send('파일 업로드 성공'); }); app.listen(3000, () => { console.log('서버가 3000번 포트에서 실행 중'); });
- connect-multiparty:
connect-multiparty
를 사용한 파일 업로드 예제const express = require('express'); const multiparty = require('connect-multiparty'); const app = express(); const multipartyMiddleware = multiparty(); app.post('/upload', multipartyMiddleware, (req, res) => { const files = req.files; for (const key in files) { const file = files[key]; console.log(`파일 이름: ${file.originalFilename}`); console.log(`파일 경로: ${file.path}`); } res.send('파일 업로드 성공'); }); app.listen(3000, () => { console.log('서버가 3000번 포트에서 실행 중'); });
- connect-busboy:
connect-busboy
를 사용한 파일 업로드 예제const express = require('express'); const connectBusboy = require('connect-busboy'); const app = express(); app.use(connectBusboy()); app.post('/upload', (req, res) => { req.busboy.on('file', (fieldname, file, filename) => { console.log(`파일 이름: ${filename}`); file.on('data', (data) => { console.log(`파일 데이터: ${data.length} 바이트`); }); file.on('end', () => { console.log('파일 업로드 완료'); }); }); req.busboy.on('finish', () => { res.send('파일 업로드 성공'); }); }); app.listen(3000, () => { console.log('서버가 3000번 포트에서 실행 중'); });