<bdo id='0oDN0'></bdo><ul id='0oDN0'></ul>
  • <tfoot id='0oDN0'></tfoot>
  • <i id='0oDN0'><tr id='0oDN0'><dt id='0oDN0'><q id='0oDN0'><span id='0oDN0'><b id='0oDN0'><form id='0oDN0'><ins id='0oDN0'></ins><ul id='0oDN0'></ul><sub id='0oDN0'></sub></form><legend id='0oDN0'></legend><bdo id='0oDN0'><pre id='0oDN0'><center id='0oDN0'></center></pre></bdo></b><th id='0oDN0'></th></span></q></dt></tr></i><div id='0oDN0'><tfoot id='0oDN0'></tfoot><dl id='0oDN0'><fieldset id='0oDN0'></fieldset></dl></div>
  • <legend id='0oDN0'><style id='0oDN0'><dir id='0oDN0'><q id='0oDN0'></q></dir></style></legend>

      1. <small id='0oDN0'></small><noframes id='0oDN0'>

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

        How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
        • <tfoot id='TEwY7'></tfoot>
        • <small id='TEwY7'></small><noframes id='TEwY7'>

          <legend id='TEwY7'><style id='TEwY7'><dir id='TEwY7'><q id='TEwY7'></q></dir></style></legend>
            <bdo id='TEwY7'></bdo><ul id='TEwY7'></ul>

            <i id='TEwY7'><tr id='TEwY7'><dt id='TEwY7'><q id='TEwY7'><span id='TEwY7'><b id='TEwY7'><form id='TEwY7'><ins id='TEwY7'></ins><ul id='TEwY7'></ul><sub id='TEwY7'></sub></form><legend id='TEwY7'></legend><bdo id='TEwY7'><pre id='TEwY7'><center id='TEwY7'></center></pre></bdo></b><th id='TEwY7'></th></span></q></dt></tr></i><div id='TEwY7'><tfoot id='TEwY7'></tfoot><dl id='TEwY7'><fieldset id='TEwY7'></fieldset></dl></div>

                  <tbody id='TEwY7'></tbody>
                  本文介绍了如何使用 Fetch API 下载和保存文件?(Node.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have the url to a possibly large (100+ Mb) file, how do I save it in a local directory using fetch?

                  I looked around but there don't seem to be a lot of resources/tutorials on how to do this.

                  Thank you!

                  解决方案

                  Using the Fetch API you could write a function that could download from a URL like this:

                  const downloadFile = (async (url, path) => {
                    const res = await fetch(url);
                    const fileStream = fs.createWriteStream(path);
                    await new Promise((resolve, reject) => {
                        res.body.pipe(fileStream);
                        res.body.on("error", reject);
                        fileStream.on("finish", resolve);
                      });
                  });
                  

                  这篇关于如何使用 Fetch API 下载和保存文件?(Node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                  can#39;t get response status code with JavaScript fetch(无法使用 JavaScript 获取响应状态代码)
                  <legend id='3UKUe'><style id='3UKUe'><dir id='3UKUe'><q id='3UKUe'></q></dir></style></legend>

                      <tbody id='3UKUe'></tbody>

                      <small id='3UKUe'></small><noframes id='3UKUe'>

                      <i id='3UKUe'><tr id='3UKUe'><dt id='3UKUe'><q id='3UKUe'><span id='3UKUe'><b id='3UKUe'><form id='3UKUe'><ins id='3UKUe'></ins><ul id='3UKUe'></ul><sub id='3UKUe'></sub></form><legend id='3UKUe'></legend><bdo id='3UKUe'><pre id='3UKUe'><center id='3UKUe'></center></pre></bdo></b><th id='3UKUe'></th></span></q></dt></tr></i><div id='3UKUe'><tfoot id='3UKUe'></tfoot><dl id='3UKUe'><fieldset id='3UKUe'></fieldset></dl></div>

                          <bdo id='3UKUe'></bdo><ul id='3UKUe'></ul>
                          <tfoot id='3UKUe'></tfoot>