加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

将文件传输到webworker:DataCloneError:无法克隆该对象

发布时间:2020-12-14 18:41:15 所属栏目:资源 来源:网络整理
导读:我想将文件从表单传输到webworker.在chrome i中,simple可以使用此代码来传输FileList-Object: worker.postMessage(files: array_files); 但是使用Firefox我得到了这个错误: Transfer file to webworker: DataCloneError: The object could not be cloned.
我想将文件从表单传输到webworker.在chrome i中,simple可以使用此代码来传输FileList-Object:
worker.postMessage(files: array_files);

但是使用Firefox我得到了这个错误:

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

所以我试图将语法用于可转移对象.像这样的东西?

var post = {files: array_files,file_ids: response.file_ids};
worker.postMessage(post,[post]);

但是,我在Chrome中得到了这个

Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': Value at index 0 does not have a transferable type.

还是

DataCloneError: The object could not be cloned.

在Firefox中.

将FileList传递给worker的正确方法是什么?

解决方法

我不知道如何使用postMessage传递File对象,但至少我可以建议可转移对象不能以这种方式工作.可选的第二个参数是您希望传递的任何类型化数组的后备ArrayBuffer实例的数组.因此,例如,假设您要发布的消息是结构化对象:
var message = {foo: 'abc',bar: new Uint8Array(...)};

worker.postMessage(message,[message.bar.buffer])

另请注意,将类型化数组作为可传输对象传递给另一个工作者/窗口会使传输的数组无法从发送工作者/窗口访问.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读