我正在尝试上传视频 [英] I was trying to upload a video

查看:107
本文介绍了我正在尝试上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下代码后,我们将视频添加到"blob: http://localhost:8080/2d118b17-34b3-4e19-8044-72e9a0c5eaff " formate.我想将Blob网址转换为字节数组.

After doing the below code, we getting the video in "blob:http://localhost:8080/2d118b17-34b3-4e19-8044-72e9a0c5eaff"" formate. I want to convert the blob url into byte array.

有人可以帮助我将bloburl转换为字节数组吗?

Can anyone please help me to convert bloburl into byte array?

我的HTML:

<video ng-if="item.documentType == 'video'" controls  width="100" height="145">
     <source data-ng-src="{{item.data}}">
     Your browser does not support the video tag.
</video>

我的JS:

if(type == 'video'){            
    var item = {
        name:file.files[0].name,
        documentType:type,
        src: file.files[0],
        data: URL.createObjectURL(file.files[0]),
        caseFileId: $scope.mediaItem.caseId
    }

    $scope.mediaItem.listDocumentDto.push(item);            
}

推荐答案

您需要使用 ArrayBuffer ,然后您可以使用您选择的TypedArray .

You need to use FileReader to get the contents of the file into a ArrayBuffer which you can then use a TypedArray of your choice.

var fr = new FileReader();
fr.onloadend = function(){
  //fr.result will be an ArrayBuffer so create an Int8Array view
  var data = new Int8Array(fr.result);
  //use data as you wish.
};
fr.readFileAsArrayBuffer(file.files[0]);

这篇关于我正在尝试上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆