Transfer file to webworker: DataCloneError: The object could not be cloned

后端 未结 1 1411
心在旅途
心在旅途 2021-01-11 16:41

I want to transfer a file from a form to a webworker. In chrome i simple can use this code to transfer a FileList-Object:

worker.postMessage(files: array_fil         


        
相关标签:
1条回答
  • 2021-01-11 16:58

    I don't know how to pass File objects with postMessage, but at the least I can advise that transferable objects do not work in this way. The optional second parameter is an array of the backing ArrayBuffer instances of any typed arrays you wish to pass. So for instance, suppose the message you would like to post is a structured object:

    var message = {foo: 'abc', bar: new Uint8Array(...)};
    
    worker.postMessage(message, [message.bar.buffer])
    

    Also notice that passing a typed array to another worker/window as a transferable object makes the transferred array inaccessible from the sending worker/window.

    0 讨论(0)
提交回复
热议问题