js传递二进制视频数据的方法

JavaScript011

js传递二进制视频数据的方法,第1张

js传递二进制视频数据的方法是以下这些。

1、用js操作二进制数据,通过socket与后台进行传输。将二进制数据存放在其中。

2、通过此方式,我们可以直接在网络中传输二进制内容。

async downloadFile() {

const cname = this.loginUser.username

const params = await this.getParams()//自己写的获取参数方法

axios({

url: ${baseURL}/download ,

method: 'post',

data: params,

responseType: 'blob',

headers: {

cid: this.customerCode

}

}).then(res =>{

const fileName = wifi预警_${cname}.csv

var blob = res.data

if ('msSaveOrOpenBlob' in navigator) {

window.navigator.msSaveOrOpenBlob(blob, fileName) //IE导出

} else {

let url = window.URL.createObjectURL(new Blob([blob]))

let link = document.createElement('a')

link.style.display = 'none'

link.href = url

link.setAttribute('download', fileName)

link.click()

}

})

},

使用FileReader对象,web应用程序可以异步的读取存储在用户计算机上的文件(或者原始数据缓冲)内容,可以使用File对象或者Blob对象来指定所要处理的文件或数据.

readAsBinaryString()

读取指定的Blob对象或File对象中的内容. 当读取操作完成时,readyState属性的值会成为DONE,如果设置了onloadend事件处理程序,则调用之.同时,result属性中将包含所读取文件的原始二进制数据.