Large file upload with WebSocket

后端 未结 6 2049
自闭症患者
自闭症患者 2020-11-30 00:24

I\'m trying to upload large files (at least 500MB, preferably up to a few GB) using the WebSocket API. The problem is that I can\'t figure out how to write \"send this slice

6条回答
  •  鱼传尺愫
    2020-11-30 00:43

    I believe the send() method is asynchronous which is why it will return immediately. To make it queue, you'd need the server to send a message back to the client after each slice is uploaded; the client can then decide whether it needs to send the next slice or a "upload complete" message back to the server.

    This sort of thing would probably be easier using XMLHttpRequest(2); it has callback support built-in and is also more widely supported than the WebSocket API.

提交回复
热议问题