问题已解决 [代码]return[代码] [代码]new[代码] [代码]Promise([代码][代码]function[代码] [代码](resolve, reject) {[代码][代码] [代码][代码]request(options, (error, response, body) => {[代码][代码] [代码][代码]let jsonBody = JSON.parse(body)[代码][代码] [代码][代码]downUrl = jsonBody.download_url[代码][代码] [代码][代码]const fileName = [代码][代码]'/tmp/file.mp4'[代码][代码] [代码][代码]// let p = path.join(__dirname, 'tmp/file.mp4')[代码][代码] [代码][代码]request(downUrl).pipe(fs.createWriteStream(fileName)).on([代码][代码]'close'[代码][代码], () => {[代码][代码] [代码][代码]const fileStream = fs.createReadStream(fileName)[代码][代码] [代码][代码]resolve(cloud.uploadFile({[代码][代码] [代码][代码]cloudPath: [代码][代码]'file.mp4'[代码][代码],[代码][代码] [代码][代码]fileContent: fileStream,[代码][代码] [代码][代码]})[代码][代码] [代码][代码])[代码] [代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码]
云函数下载文件保存到临时文件再读取的时候报错,为什么?[代码]const cloud = require([代码][代码]'wx-server-sdk'[代码][代码])[代码][代码]const request = require([代码][代码]'request'[代码][代码])[代码][代码]const fs = require([代码][代码]'fs'[代码][代码])[代码][代码]const path = require([代码][代码]'path'[代码][代码])[代码] [代码]return[代码] [代码]new[代码] [代码]Promise([代码][代码]function[代码] [代码](resolve, reject) {[代码][代码] [代码][代码]request(options, (error, response, body) => {[代码][代码] [代码][代码]let jsonBody = JSON.parse(body)[代码][代码] [代码][代码]downUrl = jsonBody.download_url[代码][代码] [代码][代码]let p = path.join(__dirname, [代码][代码]'/tmp/file.mp4'[代码][代码])[代码][代码] [代码][代码]request(downUrl).pipe(fs.createWriteStream(p)).on([代码][代码]'close'[代码][代码], () => {[代码][代码] [代码][代码]const fileStream = fs.createReadStream(p)[代码][代码] [代码][代码]resolve(cloud.uploadFile({[代码][代码] [代码][代码]cloudPath: [代码][代码]'file.mp4'[代码][代码],[代码][代码] [代码][代码]fileContent: fileStream,[代码][代码] [代码][代码]})[代码][代码] [代码][代码])[代码] [代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码] ##报错日志 2019-08-10T03:38:05.684Z { Error: ENOENT: no such file or directory, open '/var/user/tmp/file.mp4' errno: -2, code: 'ENOENT', syscall: 'open', path: '/var/user/tmp/file.mp4' } END RequestId: 430c6bf0-bb20-11e9-9e13-5254007aa7a1 Report RequestId: 430c6bf0-bb20-11e9-9e13-5254007aa7a1 Duration:797ms Memory:256MB MaxMemoryUsed:3.015625MB
2019-08-10