1

I want to send a zip from my kuzzle backend so i wrote that in my backend:

// Generate zip file
    const zip = new JSZip()
    zip.file(filename, zipData)
    const finalZipFile = await zip.generateAsync({
      type:"nodebuffer",
      compression: "DEFLATE",
      compressionOptions: {
        level: 6
      }
    })
req.response.configure({
      // Tell Kuzzle that this result will contain a raw payload
      format: 'raw', 
      headers: {
        // Set HTTP response headers
        'Content-Length': finalZipFile.length.toString(),
        'Content-Type': 'application/zip',
        'Content-Disposition': `attachment; filename="${filenameBase + ".zip"}"`,
        'Cache-Control': 'no-cache'
      }
    });
    return finalZipFile;

But when i make a request using the nodejs sdk:

const result = await kuzzle.query({
      controller: "hahaha",
      action: "hahaha"
    })
    console.log(result)

i get an error message:

/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/kuzzle-sdk/src/KuzzleError.js:32
        super(apiError.message);
                       ^

TypeError: Cannot read properties of undefined (reading 'message')
    at new KuzzleError (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/kuzzle-sdk/src/KuzzleError.js:32:24)
    at WebSocket.client.onmessage (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/kuzzle-sdk/src/protocols/WebSocket.js:159:35)
    at WebSocket.onMessage (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:520:28)
    at Receiver.receiverOnMessage (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/websocket.js:1137:20)
    at Receiver.emit (node:events:520:28)
    at Receiver.dataMessage (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/receiver.js:528:14)
    at Receiver.getData (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/receiver.js:446:17)
    at Receiver.startLoop (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/receiver.js:148:22)
    at Receiver._write (/Users/doriancruveiller/Desktop/kuzzle-plugin-test/node_modules/ws/lib/receiver.js:83:10)

But the weird thing is that it works just fine if i do the same request with wscat. Maybe a bug in the nodeJS sdk ?

d.cruveiller
  • 113
  • 7

1 Answers1

1

Most likely you just hit the server.maxRequestSize limit of the network layer.

You should increase this limit to send bigger files to Kuzzle.

Also, consider using S3 based storage with Pre-signed URLsinstead of storing file directly on Kuzzle because this will not works properly in a cluster environment.

Aschen
  • 1,691
  • 11
  • 15
  • i tried to put server.maxRequestSize to 3GB, i see it in app.config but it still does not work as i am getting the same error message – d.cruveiller Aug 29 '22 at 14:17
  • I think I just figured your issue, since the response is a raw zip file, it cannot be parsed by the SDK. You need to expose your API action through HTTP, then if you are in a browser then just generate the corresponding HTTP link and if you are in Node.js then use an HTTP lib to download it – Aschen Aug 30 '22 at 06:36