我尝试调用一个rest api,它返回一个带有 Content-Type: application/pdf 和 Content-Encoding: gzip 的文件响应
如何下载此文件并可以从本地驱动器打开?
我使用以下代码:
import { RequestOptions, RESTDataSource } from 'apollo-datasource-rest';
import * as fs from 'fs';
export class DocumentManagementService extends RESTDataSource {
async downloadDocument(id: string): Promise<any> {
const response = await this.get<any>(
`/documents/${id}/download`,
undefined,
{}
);
fs.writeFileSync('test.pdf', response, 'binary');
}
}
有人可以帮我下载这个文件吗?