相关疑难解决方法(0)

如何从JS中的ArrayBuffer编写文件

我正在尝试为Meteor框架编写一个文件上传器.原理是将客户端上的文件从ArrayBuffer拆分为4096位的小包,通过Meteor.method发送到服务器.

下面简化的代码是客户端向服务器发送一个块的部分,它会重复,直到offset到达data.byteLength:

// data is an ArrayBuffer
var total = data.byteLength;
var offset = 0;

var upload = function() {
  var length = 4096; // chunk size

  // adjust the last chunk size
  if (offset + length > total) {
     length = total - offset;
  }

  // I am using Uint8Array to create the chunk
  // because it can be passed to the Meteor.method natively
  var chunk = new Uint8Array(data, offset, length);

  if (offset …
Run Code Online (Sandbox Code Playgroud)

javascript file-upload node.js arraybuffer meteor

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

arraybuffer ×1

file-upload ×1

javascript ×1

meteor ×1

node.js ×1