我正在尝试使用xhr进行异步文件上传:
这是我的前端代码:
...
$el = $(selector)
el = $el.get 0 // Worls
data = new FormData()
data.append "file", el.files[0]
$.ajax
url: "//#{window.config.host}/api/v1/versions/..."
type: "POST"
data: data
processData: false
success: (data) ->
console.log data
后端(bodyParser设置)
app.bodyParser = express.bodyParser
keepExtensions:true,
uploadDir: path.join __dirname,'/temp/'
发送的标题:
Host: localhost:1234
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0
Accept: */*
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:9000/
Content-Length: 323651
Origin: http://localhost:9000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
请求正文发送
-----------------------------13495352912601
Content-Disposition: form-data; name="file"; filename="logo.png"
Content-Type: image/png
PNG
...
Å !ýâB!Ìe>ýÌ×<:ìî×w'<ôïÜ¢ïý÷ï¶}Ú=ýçûÒ¸ï¼r{ߣ§fÐñÝâ¤
'µâþAqB!Bf3Ñü¿}ԣà LÞõкM;¿èVßþÏÝ~üûòëÓ
xÉKqBqÒw(Né'B!d6ca"¿ys%Wï¿Å/8A¸¤é%'=Á¬5IEND®B`
-----------------------------13495352912601--