filereader

Angular2 + Typescript + FileReader.onLoad = property does not exist

二次信任 提交于 2019-12-04 16:09:07
问题 I am using the FileReader Interface and it’s asynchronous method readAsText() to read a local text file, After that when the onload event is called, I try to read my file, my source code is something like the following: export class ReadFileComponent { text: string; readFile(): void { let reader=new FileReader(); reader.onload = function(e) { this.text=reader.result; } reader.readAsText(file); } } compilation is failed because Property "text" does not exist on type "FileReader" I think this

Difference between readAsBinaryString() and readAsDataURL() in HTML5 FileReader API

天大地大妈咪最大 提交于 2019-12-04 15:08:44
In the HTML5, it introduced the FileReader API. I can't really understand the difference between readAsBinaryString() and readAsDataURL(). I read docs from several places, but still can't fully understand. Can someone give some code examples to help me understand the differences? If you use the readAsDataURL() you get the data back in a data URI format. So something like the src attribute here: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot"> If you use the readAsBinaryString()

JavaScript delete File from FileList to be uploaded

妖精的绣舞 提交于 2019-12-04 14:45:43
There is the code https://jsfiddle.net/bfzmm1hc/1 Everything looks fine but I want to delete some of the files from the set. I have already found these: How to remove one specific selected file from input file control input type=file multiple, delete items I know that FileList object is readonly, so I can just copy the files to a new array. But what should I do with this new array of File objects? I can't assign it to the files property... Since you cannot edit the Read Only input.files attribute, you must upload a form using XMLHttpRequest and send a FormData object . I will also show you how

Angular 4.x + Cordova : FileReader fails silently (white screen of death)

梦想的初衷 提交于 2019-12-04 14:10:35
I have an Angular 4.3 + Cordova application that used to work very well. But now, I get a blank screen on app start-up, and nothing happens any more. After digging a while I realized where it comes from : my home page is protected by a CanActivate guard that will check some file-system-persisted preferences and redirect the user to another page if this is the first run or if a required preference is missing, to fill-in the required properties. So the launch of the app depends on my CanActivate guard that depends on a PreferenceService that itself depends on a FileSystemService that I

HTML5 FileReader API crashes chrome 17 when reading large file as slice

喜夏-厌秋 提交于 2019-12-04 13:13:29
I'm trying to read large file (3GB) as slice as 100Mb. ***function sliceMe() { var file = document.getElementById('files').files[0], fr = new FileReader; var chunkSize = document.getElementById('txtSize').value; chunkSize =1048576; var chunks = Math.ceil(file.size / chunkSize); var chunk = 0; document.getElementById('byte_range').innerHTML = ""; function loadNext() { var start, end, blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice; start = chunk * chunkSize; if (start > file.size) start = end+1; end = start + (chunkSize -1) >= file.size ? file.size : start + (chunkSize -1); fr

How to Upload images from FileReader to Amazon s3, using meteor

房东的猫 提交于 2019-12-04 11:09:40
问题 Im trying to build an image uploader with meteor to Amazon S3. Thanks to Hubert OG, Ive found AWS-SDK which makes things easy. My problem is that the data uploaded seems to be corrupt. When I download the file it says, the file may be corrupt. Probably it is. Inserting the data into an image src, does work, and the preview of the image shows up as it supposed to, so the original file, and probably the data is correct. I'm loading the file with FileReader, and than pass the result data to AWS

Alternative to readAsBinaryString for IE10

十年热恋 提交于 2019-12-04 10:47:43
问题 It seems that readAsBinaryString, a method of the JavaScript FileReader object, is not supported in IE10. I've tried the following, as suggested in this HTML5 Rocks article: String.fromCharCode.apply(null, new Uint16Array(buffer)); However, this results in an Out of stack space error. 回答1: I found the answer here: var binary = ""; var bytes = new Uint8Array(buffer); var length = bytes.byteLength; for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); } 回答2: If you'd like

Is it possible to clean memory after FileReader?

牧云@^-^@ 提交于 2019-12-04 08:37:55
问题 FileReader seems to consume all the memory as it is repeatedly used to preload multiple blobs, and never frees it. Any known way to force it to release consumed memory? Setting FileReader object and it's result property to null doesn't seem to work. UPDATE: Here is a sample code (test it on a big files, like movie, or you won't notice the effect in task manager): <input id="file" type="file" onchange="sliceMe()" /> <script> function sliceMe() { var file = document.getElementById('file').files

JS - File Reader API get image file size and dimensions

半城伤御伤魂 提交于 2019-12-04 07:12:16
Hi i'm using the following code to get the upload image using File Reader API: <script type="text/javascript"> var loadImageFile = (function () { if (window.FileReader) { var oPreviewImg = null, oFReader = new window.FileReader(), rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\

Understanding how BufferedReader works in Java

夙愿已清 提交于 2019-12-04 07:10:12
Very basic question on how BufferedReader works. Given the string/phrase, I want to find and print it from the file with a lot of text in it. using BufferedReader in Java I did some research on this topic and that was the closest result. Not quite addressing my problem though. So with this information, why does the following code terminate? public class MainApp { String line = null; String phrase = "eye"; try { File file = new File("text.txt"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); while((line = br.readLine()) != null) { if (line.equals(phrase) {