在Node.js文档的Streams部分中,它说我可以使用"fs.createReadStream(url || path)"。但是,当我实际这样做时,它告诉我"Error: ENOENT: no such file or directory"。我只想将视频从可读流传输到可写流中,但我卡在了创建可读流的步骤中。
我的代码:
const express = require('express')
const fs = require('fs')
const url = 'https://www.example.com/path/to/mp4Video.mp4'
const port = 3000
app.get('/video', (req, res) => {
const readable = fs.createReadStream(url)
})
app.listen(port, () => {
console.log('listening on port ' + port)
})
错误:
listening on port 3000
events.js:291
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open 'https://www.example.com/path/to/mp4Video.mp4'
Emitted 'error' event on ReadStream instance at:
at internal/fs/streams.js:136:12
at FSReqCallback.oncomplete (fs.js:156:23) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: 'https://www.example.com/path/to/mp4Video.mp4'
}
提示:https://www.example.com/path/to/mp4Video.mp4 不是实际的URL。
https.get
返回流吗?所以我可以像这样做const myStream = https.get(mp4Url)
吗?我最终想要将其与fluent-ffmpeg
一起使用。 - Optymystychttps.get()
返回302响应,则该响应将直接传递给响应,因为https.get()
不会自动跟随302响应。 - jfriend00