本文介绍了强大的nodejs不会触发任何事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在express3.x上并且使用强大

I am on express3.x and using formidable

app.post "/up",(req,res)->
formidable = require('formidable')
form = new formidable.IncomingForm()
form.uploadDir = __dirname + "/uploads"
form.encoding = 'binary'


form.addListener 'file',(name,file) ->
    #write file
    console.log('file uploaded')
    return
console.log('$$$$$$$$$$$')
form.addListener 'end', ->
    console.log('end')
    res.end()
    return
console.log('@@@@@$$$$')
form.parse req,(err,fields,files)->
    console.log('parse')
    console.log(err) if(err)
    return
console.log('######')
return

,上传表单为

block content
:coffeescript
    $ ->
        formData = new FormData()
        xhr = new XMLHttpRequest()
        onProgress = (e)->
            per_complete = (e.loaded/e.total) * 100 if e.lengthComputable

        onReady = (e)->
            alert("Ready")

        onError = (err)->
            alert("Error Loading "+err)

        $('#upload').click (e)->
            formData.append('img',document.getElementById('img').files[0])
            xhr.open('post','/up',true)
            xhr.addEventListener('error',onError,false)
            xhr.addEventListener('progress',onProgress,false)
            xhr.send(formData)
            xhr.addEventListener('readystatechange',onReady,false)

h1 hello world
form
    |select Image:
    input(type='file',name='img', id='img')
    input(type='button',value='button', id='upload')

没有任何事件被触发...不知道我在想什么.

none of events are getting triggered...Not sure what am I my missing..

推荐答案

(如果使用app.use(express.bodyParser())等效于:

app.use(express.json());
app.use(express.urlencoded());
app.use(express.multipart());

您可以删除app.use(express.multipart());,然后可以使用强大的对象.

you can remove app.use(express.multipart()); then you can use formidable object.

这篇关于强大的nodejs不会触发任何事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:57