filereader

return value calculated from javascript FileReader onload event [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-07-18 11:50:33
问题 This question already has answers here : How do I return the response from an asynchronous call? (39 answers) Closed 9 days ago . I have this function: function doStuff(range, file) { var fr = new FileReader(); var hash = ''; fr.onload = function (e) { var out = "stuff happens here"; hash = asmCrypto.SHA256.hex(out); return hash; }; fr.readAsArrayBuffer(file); return hash; } Right now, the function completes before the onload event is finished, so doStuff always returns "". I think a callback

Proper way to read a file using FileReader() to generate an md5 hash string from image files?

我与影子孤独终老i 提交于 2020-06-22 04:28:17
问题 I'm currently doing this (see snippet below) to get an md5 hash string for the image files I'm uploading (I'm using the hash as fileNames ): NOTE: I'm using the md5 package to generate the hash (it's loaded into the snippet). There are 4 available methods on FileReader() to read the files. They all seem to produce good results. readAsText(file) readAsBinaryString(file); readAsArrayBuffer(file); readAsDataURL(file); Which is should I be using in this case and why? Can you also explain the

html5-FileReader接口

ε祈祈猫儿з 提交于 2020-04-18 00:23:45
<!-- html 部分 --> <h5>html-FileReader</h5> <input id="upload " type="file" accept="image/*"> <img id="img" src=""> <!-- js 部分 --> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $('#upload').change(function(){ var reader = new FileReader() reader.onload = function(){//文件读取完成时 出发onload事件 var result = reader.result; //base64 编码的文件存在FileReader.result中 $('#img').attr('src',result); //选中文件转换为 Blob对象 var blob = dataURItoBlob(result); console.log(blob) } reader.readAsDataURL(this.files[0]); //获取base64 编码

Is it possible to cut part of video and upload it on server only with html5 & js

℡╲_俬逩灬. 提交于 2020-04-11 04:30:00
问题 I use Filereader to read local video file (mp4), so I can display it in video tag. I need to cut part of mp4 file (i.e. from 5 to 10 seconds) and upload it on server. My current solution: I upload whole video file on server with "from" and "to" parameters, cut it with ffmpeg on server, upload to s3 and return the url video. Maybe is it possible only with JS/HTML? I found Blob.slice method but i didn't know how to use it to cut video parts. Thanks! 回答1: An mp4 video file is made up of 'atoms'