相关疑难解决方法(0)

将本机获取主体网络流转换为节点流时打字稿错误

包.json

{
  "type": "module",
  "dependencies": {
    "@types/node": "^18.6.5",
    "typescript": "^4.7.4"
  }
}
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "ESNext",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
Run Code Online (Sandbox Code Playgroud)

使用节点 v18.7.0,我尝试将从本机 fetch API 返回的网络流转换为节点流。我使用“node:stream”模块中的 Readable.fromWeb 方法。Typescript 返回类型检查错误,但代码使用 @ts-ignore 注释按预期工作。

类型错误

 Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'ReadableStream<any>'.
  Type 'ReadableStream<Uint8Array>' is missing the following properties from type 'ReadableStream<any>': values, [Symbol.asyncIterator]

const nodeStream = Readable.fromWeb(fetchRequest.body)
Run Code Online (Sandbox Code Playgroud)

源代码

 Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of …
Run Code Online (Sandbox Code Playgroud)

node.js typescript fetch-api node-streams

11
推荐指数
1
解决办法
2305
查看次数

如何使用Fetch API下载和保存文件?(Node.js)

我有一个可能很大的文件(100+ Mb)的url,如何使用访存将其保存在本地目录中?

我环顾四周,但是关于如何执行此操作似乎没有很多资源/教程。

谢谢!

javascript xmlhttprequest fetch node.js fetch-api

9
推荐指数
4
解决办法
6440
查看次数

如何使用 node.js 下载视频 mp4 文件?

我想让用户从我的 AWS S3 存储桶下载视频。视频格式为MP4:

app.get("/download_video", function(req,res) {
    filename = "s3.xxx.amazon.com/bucketname/folder/video_example.mp4";
    // im stuck on what i can do here
});
Run Code Online (Sandbox Code Playgroud)

有很多关于如何使用nodejs在线下载图像和文本文件的示例,但我在视频上找不到任何内容。

javascript node.js express

1
推荐指数
1
解决办法
2万
查看次数