详解如何在Node.js的httpServer中接收前端发送的arraybuffer数据

2020-06-17 06:39:31易采站长站整理

pointXhr.send(null);

前端接收图片buffer


let imageXhr = new XMLHttpRequest()
imageXhr.onreadystatechange = function () {
  var DONE = imageXhr.DONE || 4;
  if (imageXhr.readyState === DONE) {
    if (imageXhr.response) {
      let bufferArray = imageXhr.response
      let uint8Array = new Uint8Array(bufferArray);
      for (var i = 0; i < bufferArray.length; ++i) {
      uint8Array[i] = bufferArray[i];
    }
    callback(uint8Array)
    }
  }
}
imageXhr.open("POST",url,true);
imageXhr.responseType = 'arraybuffer';
imageXhr.send(null);