首页 > 其他分享 >How to get the Axios's response file type All In One

How to get the Axios's response file type All In One

时间:2023-08-26 14:24:01浏览次数:38  
标签:Axios console log get How axios type response headers

How to get the Axios's response file type All In One

获取 Axios 请求响应头中的文件类型

Axios API

https://www.npmjs.com/package/axios

demos

import fs from 'node:fs';
import path from 'path';
import axios from 'axios';

async function downloadFile(url, path) {
  const writer = fs.createWriteStream(path);
  const res = await axios({
    url,
    method: "GET",
    responseType: "stream",
  });
  // console.log(`res =`, res)
  console.log(`✅ content-type =`, res.headers['content-type'])
  res.data.pipe(writer);
  return new Promise((resolve, reject) => {
    writer.on("finish", resolve);
    writer.on("error", reject);
  });
}


const url = `https://cdn.xgqfrms.xyz/video/web-testing.mp4`
await downloadFile(url, "./test.mp4");
// ✅ content-type = video/mp4

/*

$ node ./file-type.js

*/
import axios from 'axios';

async function getUser() {
  try {
    const response = await axios.get(
      'https://api.xgqfrms.xyz/api/users',
    );
    console.log(response.headers);
    console.log(response.headers['date']);
    console.log(response.headers['etag']);
    console.log(response.headers['connection']);
    console.log(response.headers['content-type']);
    return response.data;
  } catch (err) {
    console.log(err);
  }
}

console.log(await getUser());

(

标签:Axios,console,log,get,How,axios,type,response,headers
From: https://www.cnblogs.com/xgqfrms/p/17657447.html

相关文章

  • gui_download和ws_filename_get
    *&---------------------------------------------------------------------**&ReportZ100*&*&---------------------------------------------------------------------**&*&*&------------------------------------------------------......
  • axios.js的使用方法
    axios是一个基于Promise的HTTP客户端,可以用于浏览器和Node.js中。以下是axios的基本使用方法: 1.安装axios模块: ```npminstallaxios``` 2.引入axios模块: ```javascriptconstaxios=require('axios');``` 3.发送GET请求: ```javascriptaxios.get('/api......
  • 解决:git SSL certificate problem: unable to get local issuer certificate
    今天遇到了gitupdate失败。记录一下错误:gitSSLcertificateproblem:unabletogetlocalissuercertificate这个问题是由于没有配置信任的服务器HTTPS验证。默认,cURL被设为不信任任何CAs,就是说,它不信任任何服务器验证。找到任意一个文件夹。右键选择>GitBashHere(......
  • AWC数组显示框aw-widget初始加载时没有把数组显示出来的问题
    1、html<aw-widgetprop="data.aaaa"></aw-widget>2、model.json"aaaa":{"displayName":"aaaa","type":"STRINGARRAY","isRequired":......
  • 活动|ShowMeBug 亮相第十四届RubyConf China
    2023年8月19- 20日,ShowMeBug受邀参加在上海举办的Ruby技术大会。RubyConfChina是由RubyChina社区以非盈利形式组织的一年一度的技术交流大会,自2009年始至2023年已成功举办了十三届,我们会邀请国内外的明星开发者、知名项目/团队的负责人以及海内外技术专家来分享Rub......
  • ShowMeBug X 国信证券 | 提升金融企业技术人才识别效率,实现高效团队搭建
    国信证券股份有限公司(以下称国信证券)与ShowMeBug完成签约。ShowMeBug技术测评平台助力国信证券将招聘流程部分线上化,HR大幅减少了人才出筛时间,加速了整体招聘进程,提升了人才识别效率,推动建设更加坚实的技术人才团队。国信证券借助支持多种编程框架语言的技术测评系统 ShowMeBug......
  • 抽取数据出现ODBC data source<IP>error message for operation <SQLGetData>: <[Micr
    一、问题描述抽取数据时出现ODBCdatasource<IP>errormessageforoperation<SQLGetData>:<[Microsoft][SQLServerNativeClient10.0]InvalidDescriptorIndex>,发现查询源数据库是正常的,查询网上说是要按数据库表字段的顺序抽取数据,仔细对比之后发现原来的表和现在的表字......
  • windows wget与curl
     wget下载https://eternallybored.org/misc/wget/curl下载https://curl.se/download.html  ffmpet下载http://ffmpeg.org/......
  • js_使用axios请求图片资源, 并读取图片资源为base64格式
    情景再现:今天在写页面时遇到这么一个请求:有一张图片,默认隐藏,要求在该图片加载完毕后,执行取消隐藏的动画.目的是不要在执行动画期间图片有空白的样子.第一个想到的当然是img的onload回调函数.但是天生反骨不爱用行内元素.于是想到使用ajax请求图片资源,再使用FileR......
  • 推荐一款免费好用的远程桌面:Getscreen
    因为平时有多台设备要用,所以远程桌面是我经常要使用的工具。最近,正好看到一款不错的远程桌面软件,马上拿出来推荐给大家,如果有需要的可以看看。今天要推荐的远程桌面软件就是这款叫Getscreen的软件,推荐理由挺简单,就3点:简单易用:只需要两步就能轻松连上远程桌面第一步:在需要被......