filereader

How to read XML file using FileReader javascript?

我与影子孤独终老i 提交于 2019-12-01 23:08:04
I need to get XML from a ODF file. I tried using FileReader readAsText and readAsBinaryString but its not working. FileReader readAsText returns some special characters for odf files. with readAsBinaryString var reader = new FileReader() reader.onloadend=function(e){ var data = e.target.result; //data is not in xml format var xml = str2xml(data); //getting error /* using DOM parser for xml parsing */ } reader.readAsBinaryString(file); How can get XML from ODF file using javascript FileReader? Here's a browser-based example, but this should be applicable to other JavaScript contexts: Make a

FileReader to String

流过昼夜 提交于 2019-12-01 20:39:32
Consider the following code function readSingleFile(evt) { //Retrieve the first (and only!) File from the FileList object var myFile = evt.target.files[0]; var reader = new FileReader(); reader.readAsText(myFile); var myString = reader.toString(); alert(myString); // print - "[object FileReader]" } I try to get all the file content into String , for example if the file content is helloWorld1 helloWorld2 I will get alert of that's content . That's not how you get the result of a FileReader . Modify your code to this: function readSingleFile(evt) { //Retrieve the first (and only!) File from the

Generate the same MD5 using javascript and PHP

浪尽此生 提交于 2019-12-01 20:22:07
I am trying to build an application that needs to compare the MD5 hash of any file. Due to specific issues, before the upload, the MD5 must be generated client side, and after the upload the application needs to check it server side. My first approach was to use, at the client side, the JavaScript File API and the FileReader.ReadAs functions. Then I use the MD5 algorithm found here: http://pajhome.org.uk/crypt/md5/ Server side, I would use PHP's fopen command and the md5 function. This approach works fine when using simple text files. But, when a binary file is used (like some jpg or pdf), the

How to read file on Windows and Linux from Java

☆樱花仙子☆ 提交于 2019-12-01 14:55:43
I have a xml file located in D:\XML\RequestXML and I am reading xml file in this folder from a FileReader . In my program I hard coded the file path /XML/RequestXML/ . This works fine with the windows environment. In windows JBoss is in D:\jbossdistrib\jboss . I created the folder structure in linux /usr/XML/RequestXML/ . And add the xml in to RequestXML folder. JBoss is in /usr/jbossdistrib/jboss/ path. But my application can not find the file specified in /XML/RequestXML/ in linux environment. If I change the file path as /usr/XML/RequestXML/ it works in linux. How can I use the consistent

Java FileReader not finding files

陌路散爱 提交于 2019-12-01 14:51:21
I decided to start a new question so it can strictly focus on the FileReader errors. This is a method that takes in a file name, and a desired output name for a new file. Say the inputted filename is "hello.txt"... the method makes it something like "/home/User/hello.txt", which goes into the FileReader as a parameter. The problem is that I get this as output "/home/User/hello.txt (No such file or directory)", even though the file does exist and the directory structure and permissions are correct. I couldn't get the method to work with just referencing the file in the local directory of the

Different behavior of XmlPullParser.getInputEncoding() on API11+ and pre-API11 versions of Android

三世轮回 提交于 2019-12-01 12:39:20
I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an output file: XmlSerializer serializer = Xml.newSerializer(); FileWriter fileWriter = new FileWriter(file, false); serializer.setOutput(fileWriter); serializer.startDocument("UTF-8", true); [... Write data to the file....] This is how I try to import data from an XML file. First, I check if the encoding is correct: XmlPullParser parser = Xml.newPullParser(); FileReader reader = new FileReader(file); parser.setFeature

How to get progress when uploading file VIA XMLHttpRequest

元气小坏坏 提交于 2019-12-01 11:04:51
I am wondering how to get the progress of a file upload using XMLHTTPRequest. In Firefox the onprogress method does not fire at all, and in chrome it only fires after the file has finished uploading. function fileUpload(file) { var formData = new FormData(); formData.append('file', file); var xhr = new XMLHttpRequest(); xhr.onprogress = function(e) { alert('progress'); }; xhr.open('POST', 'post.php', true); xhr.send(formData); // multipart/form-data } Try xhr.upload.onprogress . In the XMLHttpRequest2 spec XMLHttpRequest have upload attribute. The ability to register for progress events. Both

FileReader losing data when reading PDF

我的梦境 提交于 2019-12-01 11:00:05
I have the constraint of sending data to a server in JSON format only, and I need to send a PDF file together with other form data in the JSON. I though I could make a string from it with base64 like in this solution I found on SO: let data = {foo: 1, bar: 2}; let reader = new FileReader(); reader.readAsDataURL(pdf); reader.onload = () => { data.file = reader.result; $.ajax({type: 'POST', dataType: "json", data: JSON.stringify(data), ...}); } But it happened that reader.result does not contain the whole PDF (whether I save it to file instead of sending, or get it back from the server). In a

Create structured JSON object from CSV file in JavaScript?

大城市里の小女人 提交于 2019-12-01 10:59:34
I want to create a JSON object from the contents of a CSV file. The CSV file is loaded locally via the FileReader API and that seems to work, however I am having trouble structuring the JSON in the desired way. My code for loading the CSV file looks like this: <!DOCTYPE html> <html> <body> <p>Select local CSV File:</p> <input id="csv" type="file"> <output id="out"> input file content</output> <script> var fileInput = document.getElementById("csv"), readFile = function () { var reader = new FileReader(); reader.onload = function () { // Display CSV file contents document.getElementById('out')