1.1.10 • Published 6 years ago
dotload v1.1.10
Node文件上传
How it works
Dotload reads files from local hard disk, post the formdata built by rfc rules to the remote server. Data will be parsed and saved to the disk as files. All you need is a config.js
Simple Form Type
#First boundary
--<boundary><crlf>
# Field1
Content-Disposition:form-data; name="<fieldname1>"<crlf><crlf>
<value1><crlf>
--<boundary><crlf>
# Field2
Content-Disposition:form-data; name="<fieldname2>"<crlf><crlf>
<value2><crlf>
--<boundary><crlf>
# File1
Content-Disposition:form-data; name="<fieldname3>" filename="<filename1>"<crlf>
Content-Type: <mimetype><crlf><crlf> #optional
<binary file data><crlf>
--<boundary><crlf>
# File2
Content-Disposition:form-data; name="<fieldname4>" filename="<filename2>"<crlf>
Content-Type: <mimetype><crlf><crlf> #optional
<binary file data><crlf>
# Last boundary
--<boundary>--<crlf>
Usage
edit config.js first
module.exports = {
hostname: 'localhost', //host ip
port: 9000, // port
method: 'POST',
path: '/upload',
to: '/Users/xiaowen/work/dotload/test/target/'
}
Server
- install npm i -S dotload
- vim server.js
const createServer = require('../lib/receiver')
const config = require('./config')
createServer(config)
- start server
pm2 start server.js --name receiverServer
Client
- install npm i -S dotload
- vim upload.js
const upload = require('../lib/upload')
const config = require('./config')
const uploadPath='test/source/'
upload(config,uploadPath)
- test
node test/upload.js
TODO
- remove the dependency of formidable ,parse the data using node