filereader

FileReader memory leak in Chrome

徘徊边缘 提交于 2021-02-07 03:49:40
问题 I have a webpage with file upload functionality. The upload is performed in 5MB chunks. I want to calculate hash for each chunk before sending it to the server. The chunks are represented by Blob objects. In order to calculate the hash I am reading such blob into an ArrayBuffer using a native FileReader. Here is the code: var reader = new FileReader(); var getHash = function (blob, callback) { reader.onloadend = function (e) { var hash = util.hash(e.target.result); callback(hash); }; reader

FileReader memory leak in Chrome

别来无恙 提交于 2021-02-07 03:49:26
问题 I have a webpage with file upload functionality. The upload is performed in 5MB chunks. I want to calculate hash for each chunk before sending it to the server. The chunks are represented by Blob objects. In order to calculate the hash I am reading such blob into an ArrayBuffer using a native FileReader. Here is the code: var reader = new FileReader(); var getHash = function (blob, callback) { reader.onloadend = function (e) { var hash = util.hash(e.target.result); callback(hash); }; reader

FileNotFoundException when creating a Scanner in Eclipse with Java

♀尐吖头ヾ 提交于 2021-02-05 05:43:46
问题 I'm getting a FileNotFoundException when running the following Java 6 code on Eclipse (Indigo) on Snow Leopard: import java.io.*; import java.util.*; public class readFile { public static void main(String[] args) { Scanner s = new Scanner(new FileReader("/Users/daniel/pr/java/readFile/myfile.txt")); // Line 9 } } The exception is Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException at readFile.main(readFile.java:9) My

Reading multiple images in Angular

风流意气都作罢 提交于 2021-01-29 13:15:30
问题 I'm using Angular, in a comments list, I want to display the list of comments. For every comment, I want to display its content and the profile image of its author. I get the list of comments successfully, but I get the list of images in a wrong order. I think it's a problem of synchronization. You can see below the code of the function. comments; comments_images=[]; get_comments(){ let promise = new Promise((resolve, reject) => { this.myService.course_comments(this.course.id) .toPromise()

Show files in new window

谁说我不能喝 提交于 2021-01-28 13:50:38
问题 I want to display or show my file in a new tab, but before that, I had to upload my file first I've tried to use FileReader() and I can't load the image function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#blah').attr('src', e.target.result); window.open(e.target.result); } reader.readAsDataURL(input.files[0]); } } $("#imgInp").change(function() { readURL(this); }); <script src="https://cdnjs.cloudflare.com/ajax/libs

Accessing partial results of a FileReader in Firefox

♀尐吖头ヾ 提交于 2021-01-28 11:55:57
问题 I want to use a FileReader in my web application to partially load a CSV file into the browser. However, I am not able to access partial results in Firefox 27. My application requires only the first 100k bytes of the CSV file to populate a data preview. Therefore, I setup, start, and then abort the reader after a certain amount of data has been loaded. Here is an example that works fine in Chrome 35: warn = (a...) -> console.warn a... readFile = (file,cb,limit=1e5) -> warn "start reading file

Use HTML5 File Reader and send it to Leaflet Omnivore

别说谁变了你拦得住时间么 提交于 2021-01-28 02:55:34
问题 I'm using Leaflet JavaScript and following this tutorial: https://www.html5rocks.com/en/tutorials/file/dndfiles/ I'm building a tool for my work. It allows the user to upload a CSV file with lat/long info and plot it on a map via Leaflet Omnivore. I am able to get the html5 examples to work. But, when do I do with the data it reads in? Leaflet Omnivore requires the local path to the file being uploaded like this: var testCSV = omnivore.csv('path/to/file.csv').addTo(map).on('error', function

how to mock failure of FileReader

烈酒焚心 提交于 2021-01-27 22:08:08
问题 I have a function which creates a FileReader . In that function I also set the load and error event handlers handleFileSelect(files:ArrayLike<File>){ ... let reader = new FileReader() reader.onload = this.handleReaderLoaded; reader.onerror = this.handleReaderError; reader.readAsDataURL(file); } } I want to unit-test that handleFileSelect correctly sets the error handler and that the error handler ( handleReaderError ) gets called if FileReader fails. But I can't figure out how to make the

how to mock failure of FileReader

随声附和 提交于 2021-01-27 19:57:28
问题 I have a function which creates a FileReader . In that function I also set the load and error event handlers handleFileSelect(files:ArrayLike<File>){ ... let reader = new FileReader() reader.onload = this.handleReaderLoaded; reader.onerror = this.handleReaderError; reader.readAsDataURL(file); } } I want to unit-test that handleFileSelect correctly sets the error handler and that the error handler ( handleReaderError ) gets called if FileReader fails. But I can't figure out how to make the

read a local file in javascript and output certain lines from it

孤人 提交于 2021-01-27 18:49:57
问题 I am tasked with a little coding challenge that I can't seem to work out. Its meant to be done in javascript, a language I have touched in years... Basically the task is to read a local file , which has sentences on each line. Some of the sentences are palindromes- and the goal is to output only the sentences that are palindromes. I have tried playing around in JSFiddle with the following code. But, my functionality isn't working. HTML: <input type="file" name="file" id="file"> Javascript: