0

I am trying to send uint8array in Axios payload in POST by doing this

app.post('/upload',upload.single('file') ,async function(req, res){

    var fileString = fs.readFileSync('./uploads/file.jpeg')
    var u8 = new Uint8Array(fileString);
    console.log(u8);

    try {
        const payload = {
            "binData":u8
        }

        const response = await axios.post("https://xyz/uploadservice",payload)

        res.status(200).send({"success":response})
    } catch (error) {

        res.status(400).send({"error":error})
        
    }

the xyz api endpoint expects binData in bytearray format,but its going in objects format like

binData : {"0":"23","1","255".....}

but it expects like this, binData : [23,255,.....]

Saurabh
  • 1,592
  • 2
  • 14
  • 30
  • `readFileSync(` will already be returning a Buffer, and a Buffer is a descendent Uint8Array. – Keith Nov 07 '22 at 12:05

0 Answers0