2017-01-27 1 views
0

처리를 위해 노드 서버에 보내야 할 원시 픽셀 데이터 (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.dataBuffer size does not match width and height 불평은 블롭되지 랩 Uint8Array입니다.

+0

명백한 첫 번째 단계는 BLOB를 통과하지 것이 아니라 https://www.npmjs.com/package/to처럼 뭔가를 변환하여이 사실에 uint8array입니다 노드를 말할 수 있는지 확인하는 것입니다 - 배열 버퍼 –

답변

0

블랍을 작성하는 방법이 문제가되었습니다. 하나의 TypedArray를 전달했지만 BLOB는 TypedArrays 배열을 저장하는 방법 만 알고 있습니다. 따라서 BLOB에 저장하기 전에 데이터를 문자열로 변환하고있었습니다.

해결 방안은 단순히 TypedArray를 배열로 래핑하는 것입니다.

sendBlob(new Blob([data], {type: "application/octet-stream"}), ...) 
0

게시 된 데이터에서 Uint8Array을 만듭니다.

let data = new Uint8Array(req.files.image.data); 
lwip.open(data, { 
    width: parseInt(req.body.width), 
    height: parseInt(req.body.height) 
}, (image, err) => ...) 
관련 문제