直播电商平台开发,js 前端下载后端返回的文件流

直播电商平台开发,js 前端下载后端返回的文件流

 

/**
 *
 *
 * @export
 * @param {*} fileRes文件流
 * @param {{ name: any; type: any }} fileObj文件名称和类型
 */
export function downFileByStream(
  fileRes: any,
  fileObj: { name: any; type: any }
) {
  const url = window.URL.createObjectURL(new Blob([fileRes]));
  const aLink = document.createElement("a");
  aLink.style.display = "none";
  aLink.href = url;
  //可自定义名称
  aLink.setAttribute("download", fileObj.name+'.'+fileObj.type);
  document.body.appendChild(aLink);
  aLink.click();
  document.body.removeChild(aLink);
  window.URL.revokeObjectURL(url);
}

以上就是 直播电商平台开发,js 前端下载后端返回的文件流,更多内容欢迎关注之后的文章

 

posted @ 2022-11-18 14:03  云豹科技-苏凌霄  阅读(35)  评论(0)    收藏  举报