import { parse } from 'url';
import { createServer } from 'http';
import upload from '@qingh/upload';
const port = 8080;
createServer(async (req, res) => {
const { pathname } = parse(req.url, true);
if (pathname === '/api/v1/upload') {
if (req.method.toLowerCase() === 'post') {
res.setHeader('content-type', 'application/json;charset=utf8');
try {
let data = await upload(req, res, {
uploadDir: 'upload',
type: ['jpg', 'png','gif'],
maxSize: 5 * 1024 * 1024
});
res.write('upload success');
} catch (error) {
res.write('upload fail');
}
res.end();
}
}else{
//other codes
}
}).listen(port);
-
Notifications
You must be signed in to change notification settings - Fork 0
qingh/upload
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
原生nodejs实现上传模块
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published