Hi I won't to handle upload stream by myself without touching a disk drive. So, the natural selection for me was multiparty module.
I took the general example and according the instruction from page https://npmjs.org/package/multiparty I changed form.parse to non callback request. In that case the disk won't be touched.
My code looks like this:
multiparty = require("multiparty")
http = require("http")
util = require("util")
# show a file upload form
http.createServer((req, res) ->
if req.url is "/upload" and req.method is "POST"
form = new multiparty.Form()
form.on 'error', (err) ->
console.log "Error received #{err}"
form.on 'aborted', ->
console.log "Aborted"
form.on 'part', (part) ->
console.log "Part"
form.on 'close', (part) ->
console.log "close received"
res.writeHead 200,
"content-type": "text/plain"
res.end "received upload:\n\n"
form.on 'progress', (bytesReceived, bytesExpected) ->
console.log "Received #{bytesReceived}, #{bytesExpected}"
form.parse req
else
res.writeHead 200,
"content-type": "text/html"
res.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>"
).listen 8080
the console output looks like this:
Part
Part
Received 64983, 337353
Received 130519, 337353
Aborted
Error received Error: Request aborted
The close event is not generated so I don't know when the end of reading the socket. If I change the line:
form.parse req
to:
form.parse req, (err, fields, files) ->
res.writeHead 200,
"content-type": "text/plain"
res.write "received upload:\n\n"
res.end util.inspect(
fields: fields
files: files
)
Then everything is fine and the close event is called. But the file is stored on the disk. The console looks like this:
Part
Part
Received 65536, 337353
Received 131072, 337353
Received 196608, 337353
Received 262144, 337353
Received 327680, 337353
Received 337353, 337353
close received
Any idea what's wrong?