Large file upload with WebSocket

后端 未结 6 2077
自闭症患者
自闭症患者 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:32

    Use web workers for large files processing instead doing it in main thread and upload chunks of file data using file.slice().

    This article helps you to handle large files in workers. change XHR send to Websocket in main thread.

    //Messages from worker
    function onmessage(blobOrFile) {
     ws.send(blobOrFile);
    }
    
    //construct file on server side based on blob or chunk information.
    

提交回复
热议问题