相关疑难解决方法(0)

如何使用window.fetch下载文件?

如果我想下载文件,我应该在then下面的块中做什么?

function downloadFile(token, fileId) {
  let url = `https://www.googleapis.com/drive/v2/files/${fileId}?alt=media`;
  return fetch(url, {
    method: 'GET',
    headers: {
      'Authorization': token
    }
  }).then(...);
}
Run Code Online (Sandbox Code Playgroud)

请注意,代码位于客户端.

javascript fetch fetch-api

37
推荐指数
8
解决办法
4万
查看次数

“ReadableStream<any>”类型的参数不可分配给“ReadableStream”类型的参数

我想获得一个可读形式的 Blob。

import {Readable} from 'stream';

const data: Blob = new Blob( );
const myReadable: Readable = (new Readable()).wrap(data.stream());
myReadable.pipe(ext);
Run Code Online (Sandbox Code Playgroud)

我收到此错误

ERROR in src/app/features/recorder/components/record-panel/record-panel.component.ts:80:38 - error TS2345: Argument of type 'ReadableStream<any>' is not assignable to parameter of type 'ReadableStream'.
  Type 'ReadableStream<any>' is missing the following properties from type 'ReadableStream': readable, read, setEncoding, pause, and 22 more.
Run Code Online (Sandbox Code Playgroud)

我使用 Node 14 angular 10 和 typescript

javascript stream node.js typescript

6
推荐指数
1
解决办法
1452
查看次数

如何从node.js中的URL下载PDF文件?

我正在创建一个应用程序,以从URL下载pdf文件,并以网格方式显示在我的仪表板页面中。

我正在使用带有快速框架的node.js。

exports.pdf = function(req, response) {
    var url ="http://www.ieee.org/documents/ieeecopyrightform.pdf";

    http.get(url, function(res) {
     var chunks = [];
     res.on('data', function(chunk) {
     console.log('start');
     chunks.push(chunk);
    });

    res.on("end", function() {
      console.log('downloaded');
      var jsfile = new Buffer.concat(chunks).toString('base64');
      console.log('converted to base64');
      response.header("Access-Control-Allow-Origin", "*");
      response.header("Access-Control-Allow-Headers", "X-Requested-With");
      response.header('content-type', 'application/pdf');
     response.send(jsfile);
    });
    }).on("error", function() {
   console.log("error");
   }); 
};
Run Code Online (Sandbox Code Playgroud)

pdf node.js express

5
推荐指数
2
解决办法
6449
查看次数

获取API以强制下载文件

我正在调用API来使用fetch API从服务器下载excel文件,但它没有强制浏览器下载,下面是我的标题响应:

HTTP/1.1 200 OK Content-Length: 168667 
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 
Server: Microsoft-IIS/8.5 
Content-Disposition: attachment; filename=test.xlsx 
Access-Control-Allow-Origin: http://localhost:9000 
Access-Control-Allow-Credentials: true 
Access-Control-Request-Method: POST,GET,PUT,DELETE,OPTIONS 
Access-Control-Allow-Headers: X-Requested-With,Accept,Content-Type,Origin 
Persistent-Auth: true 
X-Powered-By: ASP.NET 
Date: Wed, 24 May 2017 20:18:04 GMT
Run Code Online (Sandbox Code Playgroud)

在我用来调用API的代码下面:

this.httpClient.fetch(url, {
    method: 'POST',
    body: JSON.stringify(object),
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
})
Run Code Online (Sandbox Code Playgroud)

download aurelia fetch-api

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

标签 统计

fetch-api ×2

javascript ×2

node.js ×2

aurelia ×1

download ×1

express ×1

fetch ×1

pdf ×1

stream ×1

typescript ×1