filereader

Javascript Promises with FileReader()

半腔热情 提交于 2019-11-28 06:59:26
I have the following HTML Code: <input type='file' multiple> And Here's my JS Code: var inputFiles = document.getElementsByTagName("input")[0]; inputFiles.onchange = function(){ var fr = new FileReader(); for(var i = 0; i < inputFiles.files.length; i++){ fr.onload = function(){ console.log(i) // Prints "0, 3, 2, 1" in case of 4 chosen files } } fr.readAsDataURL(inputFiles.files[i]); } So my question is, how can I make this loop synchronous ? That is first wait for the file to finish loading then move on to the next file. Someone told me to use JS Promises. But I can't make it to work. Here's

2019-8-22学习笔记---文件上传与读取

霸气de小男生 提交于 2019-11-28 06:34:16
import { Component, OnInit } from '@angular/core'; import { _HttpClient } from '@delon/theme'; @Component({ selector: 'app-item-two', templateUrl: './item-two.component.html', styleUrls: ['./item-two.component.less'] }) export class ItemTwoComponent implements OnInit { private status = []; private mystatus; constructor(private http:_HttpClient) { } ngOnInit() { let url='http://localhost:4200/assets/myjson/mydata.json'; this.http.get(url).subscribe((res:any)=>{ this.status=res.data1 console.log(this.status) }) } myUpload(e){ console.log(e) let fileReader = new FileReader(); fileReader.onload=()

How to get duration of video when I am using filereader to read the video file?

家住魔仙堡 提交于 2019-11-28 05:40:20
问题 I am trying to upload a video to server, and on client end. I am reading it using FileReader's readAsBinaryString() . Now, my problem is, I don't know how to read duration of this video file. If i try reading the file, and assigning the reader's data to a video tag's source, then none of the events associated to the video tag are fired. I need to find the duration of file uploaded on client end. Can somebody please suggest me something? 回答1: You can do something like this for that to work:

Why is my String returning “\ufffd\ufffdN a m e”

筅森魡賤 提交于 2019-11-28 04:37:32
问题 This is my method public void readFile3()throws IOException { try { FileReader fr = new FileReader(Path3); BufferedReader br = new BufferedReader(fr); String s = br.readLine(); int a =1; while( a != 2) { s = br.readLine(); a ++; } Storage.add(s); br.close(); } catch(IOException e) { System.out.println(e.getMessage()); } } For some reason I am unable to read the file which only contains this " Name Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz " When i debug the code the String s is being returned

Reading line-by-line file in JavaScript on client side

◇◆丶佛笑我妖孽 提交于 2019-11-28 03:51:38
Could you please help me with following issue. Goal Read file on client side (in browser via JS and HTML5 classes) line by line, without loading whole file to memory. Scenario I'm working on web page which should parse files on client side. Currently, I'm reading file as it described in this article . HTML: <input type="file" id="files" name="files[]" /> JavaScript: $("#files").on('change', function(evt){ // creating FileReader var reader = new FileReader(); // assigning handler reader.onloadend = function(evt) { lines = evt.target.result.split(/\r?\n/); lines.forEach(function (line) {

Convert input=file to byte array

落花浮王杯 提交于 2019-11-28 02:03:50
I try to convert a file that i get through an input file into a byte[]. I tried with a FileReader, but i must miss something : var bytes = []; var reader = new FileReader(); reader.onload = function () { bytes = reader.result; }; reader.readAsArrayBuffer(myFile); But in the end, my bytes var doesn't content a byte array. I saw this post : Getting byte array through input type = file but it doesn't ends with a byte[], and readAsBinaryString() is deprecated What do i miss? Faced a similar problem and its true the 'reader.result' doesn't end up as 'byte[]'. So I have cast it to Uint8Array object.

How to split the strings in a file and read them?

和自甴很熟 提交于 2019-11-28 01:56:06
I have a file with information in it. It looks like: Michael 19 180 Miami George 25 176 Washington William 43 188 Seattle I want to split the lines and strings and read them. I want it to look like: Michael 19 180 Miami George ... i used a code like this: BufferedReader in = null; String read; int linenum; try{ in = new BufferedReader(new FileReader("fileeditor.txt")); } catch (FileNotFoundException e) {System.out.println("There was a problem: " + e);} try{ for (linenum = 0; linenum<100; linenum++){ read = in.readLine(); if(read == null){} else{ String[] splited = read.split("\\s+"); System

文件拖放

試著忘記壹切 提交于 2019-11-28 01:51:05
拖放 拖放是一种常见的特性,即抓取对象以后,从当前位置拖到另一个位置的过程。 dragenter 开始拖动 dragover 拖动中 dragleave 拖动放开 drop 拖动完成html 元素 <div id="target_box">把图片拖到这里试试</div> <div id="show-drop" title="拖动的图片可以在这里显示出来"></div> // js 部分 function addEventListener(dom,event,callback){ if(typeof dom == "string"){ document.querySelector(dom).addEventListener(event,callback); }else{ dom.addEventListener(event,callback); } } //开始拖动 addEventListener(document,"dragenter",function(e){ e.preventDefault(); document.querySelector("#target_box").setAttribute("class","droping"); }); //拖动中 addEventListener(document,"dragover",function(e){ e

Get base64 of audio data from Cordova Capture

若如初见. 提交于 2019-11-28 01:22:52
问题 I am using ngCordova Capture to write this code by recording audio and send the base64 somewhere (via REST). I could get the Capture Audio to work but once it returns the audioURI, I cannot get the data from the filesystem as base64. My code is below: $cordovaCapture.captureAudio(options).then(function(audioURI) { $scope.post.tracId = $scope.tracId; $scope.post.type = 'audio'; console.log('audioURI:'); console.log(audioURI); var path = audioURI[0].localURL; console.log('path:'); console.log

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.JSONArray

二次信任 提交于 2019-11-28 01:10:50
问题 I need to read a JsonArray data from a file (on an SD card) and store it into a SQLite database. but I am getting a java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.JSONArray exception while parsing data to JsonArray . Data in the file is very huge, the whole data can not be stored in a single String or String Buffer or String Builder. Here is my code. FileReader fileReader = new FileReader(file_path); Object obj = jsonParser.parse(fileReader); JSONArray