websocket 为什么用js sdk从kuzzle接收zip文件不起作用?

kokeuurv  于 2022-11-11  发布在  其他
关注(0)|答案(1)|浏览(117)

我想从我的kuzzle后端发送一个zip,所以我写在我的后端:

// 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;

但是当我使用nodejs sdk发出请求时:

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

我收到一条错误消息:

/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)

但奇怪的是,如果我用wscat做同样的请求,它就能正常工作。

hs1rzwqc

hs1rzwqc1#

最有可能的情况是,您刚刚达到了网络层的server.maxRequestSize限制。
您应该增加此限制以发送更大的文件到Kuzle。
此外,请考虑将S3 based storagePre-signed URLs一起使用,而不是直接将文件存储在Kuzzle上,因为这在集群环境中无法正常工作。

相关问题