- 分块传输不触发onChunkReceived
https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/component-plus/uploader.html const requestTask = Taro.request({ url: `${app.chatUrl}/conversation/talk`, method: "POST", enableChunked: true, responseType: "text", data: { prompt: requestQuestion, message_id: uuid(), parent_message_id: uuid(), stream: true, user_id: user_id, }, success: response => { // 开启enableChunked后,成功的回调一般用不到,因为响应数据不在这里返回 console.log(response) } }); console.log(``, requestTask); requestTask.onChunkReceived(function (response) { console.log(1) const arrayBuffer = response.data; const uint8Array = new Uint8Array(arrayBuffer); let text = String.fromCharCode.apply(null, uint8Array); console.log(`text`, text); if (text.trim() === "data: [DONE]") { setLoading(false); return; } const datas = text.split("data:"); datas.shift(); for (let i = 0; i < datas.length; i++) { const part = datas[i]; console.log(`part`, part); const datatxt = part.trim(); if (datatxt === "[DONE]") { setLoading(false); return; } else { const data = JSON.parse(datatxt); setAnswer(data.message.content.parts[0]); } } }); s数据是正常返回的,但是不触发onChunkReceived HTTP/1.1 200 transfer-encoding: chunked transfer-encoding: chunked date: Mon, 17 Jul 2023 10:08:20 GMT for-weapp-devtools: {"transfer-encoding":["chunked","chunked"],"date":["Mon, 17 Jul 2023 10:08:20 GMT"]} z这是返回头
2023-07-17 - onChunkReceived方法只触发返回了一次分块数据该怎么办?
onChunkReceived方法只触发返回了一次数据,返回的虽然确实是是分块的数据但是是一次就把全部分块的数据一下子都返回了,如下所示: [图片] 正常情况下,onChunkReceived监听 Transfer-Encoding Chunk Received 事件应该是有几个分块onChunkReceived就会触发并返回几次数据吧?请问各位大佬这是什么情况呢?服务器端(node)和前端uniapp调用的代码如下: [图片] [图片]
04-29