这就是我所拥有的 .
./upload>通过POST请求将现有的本地音频文件上传到./post_receiver
./post_receiver>接收POST请求并回复HTML页面
./record>记录要下载到本地的音频文件或通过AJAX POST请求上传到./post_receiver的音频文件
它们工作正常,但我不想使用AJAX . 我更喜欢新的HTML页面 . 我知道如何通过document.createElement(“form”),document.body.appendChild()和submit()来使用传统形式 . 但是,似乎它不能像FormData那样保存音频文件 . 顺便说一句,我的服务器是Amazon EC2上的node.js,但我认为它不相关 .
来自./record的非AJAX POST
Cannot read property 'filename' of undefined
TypeError: Cannot read property 'filename' of undefined
at router.get.html (./routes/index.js:11:74)
at Layer.handle [as handle_request] (./node_modules/express/lib/router/layer.js:95:5)
at next (./node_modules/express/lib/router/route.js:131:13)
at Object. (./node_modules/multer/lib/make-middleware.js:52:37)
at Object.immediate._onImmediate (timers.js:348:16)
at processImmediate [as _immediateCallback] (timers.js:330:15)
------WebKitFormBoundaryxh3BZE3s5vvxVQ1n
Content-Disposition: form-data; name="audio"; filename=""
Content-Type: application/octet-stream
------WebKitFormBoundaryxh3BZE3s5vvxVQ1n--
来自./record的AJAX POST或来自./upload的POST
Submit
------WebKitFormBoundary47iCp5HAMwe089e4
Content-Disposition: form-data; name="audio"; filename="audio.wav"
Content-Type: audio/wav
------WebKitFormBoundary47iCp5HAMwe089e4--
以下技巧有效,但它仍然在同一页面上,这不是我想要的 .
document.open();
document.write(.responseText);
document.close();
此外,像socket / stream / session / cookies这样的东西有点矫枉过正 . 我只是想保持简单,我希望有一种方法可以将FormData作为请求发送,让浏览器直接处理来自服务器的响应 . 如果这是不可能的,请告诉我一个简单的方法来实现这一目标 .
感谢任何想法和建议 . 谢谢 .