收藏
回答

云函数下载文件保存到临时文件再读取的时候报错,为什么?

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


最后一次编辑于  08-10  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

1 个回答

  • 高泽民
    高泽民
    08-10

    问题已解决

    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,
            })
            )
     
          })
        })
      })


    08-10
    赞同 1
    回复
问题标签