처리를 위해 노드 서버에 보내야 할 원시 픽셀 데이터 (RGBA)가 포함 된 Uint8Array
이 있습니다. 브라우저에서 blob로 변환하여 ajex를 통해 전송하지만 노드 측에서 데이터를 검색하는 것은 문제가되고 있습니다. 블럭을 Buffer
에서 req.files.image.data
까지 가져올 수는 있지만, 어떻게하면 Uint8Array
과 동일한 시퀀스로 다시 변환 할 수 있습니까? 브라우저에브라우저에서 노드로 Uint8Array를 전송하십시오.
:
sendBlob(new Blob(data, {type: "application/octet-stream"}), ...)
function sendBlob (blob, name) {
return new Promise((resolve, reject) => {
let data = new FormData()
data.append('image', blob, name)
data.append('width', 640)
data.append('height', 427)
$.ajax({
url: '/upload',
type: 'POST',
data: data,
processData: false,
contentType: false,
error: reject,
success: resolve
})
})
}
노드 서버에서 :
이lwip.open(req.files.image.data, {
width: parseInt(req.body.width),
height: parseInt(req.body.height)
}, (image, err) => ...)
이 req.files.image.data
로 Buffer size does not match width and height
불평은 블롭되지 랩 Uint8Array
입니다.
명백한 첫 번째 단계는 BLOB를 통과하지 것이 아니라 https://www.npmjs.com/package/to처럼 뭔가를 변환하여이 사실에 uint8array입니다 노드를 말할 수 있는지 확인하는 것입니다 - 배열 버퍼 –