const doc = makePdf(org, dateSuffix, bill, fileName, 2)
doc.pipe(fs.createWriteStream(`/tmp/${fileName}`))
doc.end()
console.log("create file ", fileName, " successfully in ", `/tmp/${fileName}`)
console.log("upload file to cloud: ", fileName, " to ", path)
const {
fileID
} = await uniCloud.uploadFile({
cloudPath: path,
fileContent: fs.createReadStream(`/tmp/${fileName}`)
})
console.log("upload file to cloud successfully.")
如代码所示,首先生成一个pdf文件保存到/tmp下,然后通过uniCloud.uploadFile上传,过了好长时间1分钟左右,提示错误
2022-08-09T14:43:10.847Z REPORT RequestId:55fb233c-1a30-4eb4-8837-fb8bf8fdef47 Duration:61604ms Memory:128MB MemUsage:55.913200MB
2022-08-09T14:43:10.847Z END
2022-08-09T14:43:10.847Z ERROR RequestId:55fb233c-1a30-4eb4-8837-fb8bf8fdef47 Result:{"errCode":1,"errMsg":"user code exception caught","stackTrace":"errCode: ECONNRESET | errMsg: socket hang up
Error: errCode: ECONNRESET | errMsg: socket hang up
at e.then.catch.e (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1064)
at \u003canonymous\u003e
at process._tickCallback (internal/process/next_tick.js:188:7)"}
2 个回复
e***@gmail.com (作者)
这个问题应该是读写文件时的错误,write stream没有关闭,readstream等待超时,socket hang up,我修改了之后,就没有问题了
DCloud_uniCloud_WYQ
1分钟左右是不是你配置的超时时间?不用WriteStream和ReadStream改成Buffer形式还报这个错误吗?报这个错误的时候云存储里面有上传的文件吗?用的nodejs版本是多少?