Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http')
- const url = require('url')
- const fs = require('fs')
- const multiparty = require('multiparty')
- let uploadFunc = (req, resp) => {
- req.pathname = req.pathname || url.parse(req.url).pathname
- if (req.pathname === '/upload' && req.method === 'POST') {
- let form = new multiparty.Form()
- let product = {}
- form.uploadDir = './'
- console.log(form)
- form.parse(req, function (err, fields, files) {
- resp.writeHead(200, {
- 'Contetn-Type': 'text/plain'
- })
- resp.end('Uploaded')
- })
- } else {
- resp.writeHead(200, {
- 'Content-Type': 'text/html'
- })
- resp.end(
- '<form action="/upload" enctype="multipart/form-data" method="post">' +
- '<input type="text" name="title"><br>' +
- '<input type="file" name="upload" multiple="multiple"><br>' +
- '<input type="submit" value="Upload">' +
- '</form>'
- )
- }
- }
- http
- .createServer((req, res) => {
- uploadFunc(req, res)
- })
- .listen(3333)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement