e***@gmail.com
e***@gmail.com
  • 发布:2022-08-09 15:01
  • 更新:2022-08-13 17:48
  • 阅读:917

使用uniCloud云函数上传文件至云存储报错,提示Error: errCode: ECONNRESET | errMsg: socket hang up

分类:uniCloud
    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)"}
2022-08-09 15:01 负责人:无 分享
已邀请:
e***@gmail.com

e***@gmail.com (作者)

这个问题应该是读写文件时的错误,write stream没有关闭,readstream等待超时,socket hang up,我修改了之后,就没有问题了

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

1分钟左右是不是你配置的超时时间?不用WriteStream和ReadStream改成Buffer形式还报这个错误吗?报这个错误的时候云存储里面有上传的文件吗?用的nodejs版本是多少?

该问题目前已经被锁定, 无法添加新回复