filereader

slice large file into chunks and upload using ajax and html5 FileReader

自古美人都是妖i 提交于 2019-11-28 21:38:15
What I want to implement is: In the front end, I use the html5 file api to read the file, and then upload the file's content to the php backend using ajax, and it's ok if the filesize is small. However,if the file is big enough, it causes chrome to crash. So I split the large file into chunks using file.slice, when all chunks are uploaded to the php, merge the chunks into a single complete one. the code is as follows: the front end: <style> #container { min-width:300px; min-height:200px; border:3px dashed #000; } </style> <div id='container'> </div> <script> function addDNDListener(obj){ obj

HTML5 File API: get File object within FileReader callback

谁都会走 提交于 2019-11-28 21:23:55
With the new File API in Javascript you can read files in Javascript to create dataURLs to show clientside pictures clientside. I'm wondering if you can reach the File object within the FileReader's onload callback. I will illustrate this with an example: var div = document.createElement('div'); div.ondrop = function(e) { e.preventDefault(); e.stopPropagation(); var files = e.dataTransfer.files; for ( var i=0; i<files.length; i++ ) { var file = files[i]; // this is the file I want!! var filereader = new FileReader(); filereader.onload = function(e) { this; // the FileReader object e.target; //

How can I test a change handler for a file-type input in React using Jest/Enzyme?

对着背影说爱祢 提交于 2019-11-28 21:23:27
I want to test whether my React component can use FileReader to import the contents of a user-selected file from an <input type="file"/> element. My code below shows a working component with a broken test. In my test I'm attempting to use a blob as a substitute for the file because blobs can also be "read" by FileReader . Is that a valid approach? I also suspect that part of the issue is that reader.onload is asynchronous and that my test needs to take this into consideration. Do I need a promise somewhere? Alternatively, do I perhaps need to mock FileReader using jest.fn() ? I would really

Pass a parameter to FileReader onload event

↘锁芯ラ 提交于 2019-11-28 21:18:56
I need to read some csv files, given by the user. Files are passed to the page/script using a drag and drop div, that handles the file drop as follows: function handleFileDrop(evt) { evt.stopPropagation(); evt.preventDefault(); var files = evt.dataTransfer.files; // FileList object. ... } I need to parse each file with a csv library that converts it into an array, but I also need to keep track of the file name I'm currently parsing. Here's the code I use to parse each file: for(var x = 0; x < files.length; x++){ var currFile = files[x]; var fileName = currFile.name; var reader = new FileReader

HTML5 offline storage. File storage? Directories and filesystem API

一笑奈何 提交于 2019-11-28 19:22:23
For storing data offline WebApp can use: session storage, "advanced version of cookies" key/value based Web Storage (AKA local/global/offline/DOM storage) sql-based Web SQL Database (deprecated) and Indexed Database API FileReader and FileWriter API (requires user to select files each time the application loads) But apparently there is no File Storage. Of course, there is a manifest-based caching , but it's just a cache and is not supposed to be used as a user data storage. Does it mean that the user of WebApp is forced to use some sort of a cloud file storage? Is there any way to save large

FileReader onload with result and parameter

旧街凉风 提交于 2019-11-28 18:21:10
I can't manage to get both the result of the filereader and some parameters in a onload function. This is my code: HTML of control: <input type="file" id="files_input" multiple/> Javascript function: function openFiles(evt){ var files = evt.target.files; for (var i = 0; i < files.length; i++) { var file=files[i]; reader = new FileReader(); reader.onload = function(){ var data = $.csv.toArrays(this.result,{separator:'\t'}); }; reader.readAsText(file); } } Add event: files_input.addEventListener("change", openFiles, false); I use the filereader.result , in the onload function. If I use a

对带有序号的文章进行排序

喜欢而已 提交于 2019-11-28 18:03:50
1 import java.io.*; 2 import java.util.HashMap; 3 import java.util.Map; 4 5 public class SortDemo { 6 7 public static void main(String[] args) throws IOException { 8 FileReader reader = new FileReader("src\\main\\java\\com\\nowcoder\\Gday10\\in.txt"); 9 BufferedReader bufferedReader = new BufferedReader(reader); 10 BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("D:\\shiwen.txt")); 11 // 文件的读入 12 try { 13 String readText ; 14 Map<String,String> maps = new HashMap<>() ; 15 // 重点::map中会根据key的值在自动增加排序的功能 16 char[] a = new char[1]; 17 int len = 0; 18 // 注意使用分割字符串的方法 19 // String[

Using a local file as a data source in JavaScript

淺唱寂寞╮ 提交于 2019-11-28 16:06:33
Background: I want to make an "app" that uses JavaScript/HTML only and can be opened by a browser directly from the filesystem. This app must be able to read data from another file. I'll then use JS to parse it and render pages. As a simplified example, imagine I have a CSV file (download here) : Mark Rodgers,mark.rodgers@company.com,Accounting [...] Melissa Jones,melissa@company.com,CEO I want to be able to read the file using JS and use data in it to generate my page. What I've accomplished so far: Demo (right-click -> "Save As" to save HTML to your computer). It's also available on jsfiddle

ocrad.js- OCR Javascript Library throwing Uncaught SecurityError on passing HTML5 canvas to OCRAD() API

跟風遠走 提交于 2019-11-28 14:47:09
I'm a newbie in HTML5+JS, I want to develop an hybrid app using ocrad.js . The code given below , downloaded from github page is perfectly working for me(Chrome 32.0.1). <html> <head> </head> <body> <script src="../ocrad.js"></script> <script> function OCRImage(image){ var canvas = document.createElement('canvas') canvas.width = image.naturalWidth; canvas.height = image.naturalHeight; canvas.getContext('2d').drawImage(image, 0, 0) return OCRAD(canvas) } function OCRPath(url, callback){ var image = new Image() image.src = url; image.onload = function(){ callback(OCRImage(image)) } } function

Loading CSV with FileReader to make JS Objects for Map Markers (Maps API)

瘦欲@ 提交于 2019-11-28 14:21:54
Basically I'm trying to load a csv file, parse it to an array of js objects and use those objects to make map markers with the Google Maps API. The loading works, the parsing works, all the values are correct (to my knowledge), I've been console logging to death and I get the values that I want but... my map isn't loading. I think it may be because of timing? Like the map isn't initializing or being loaded correctly. I occasionally get errors about connections timing out and security errors from the Maps API but refreshing the page and reloading the csv seems to clear that up. The errors come