filereader

Create structured JSON object from CSV file in JavaScript?

巧了我就是萌 提交于 2019-12-01 09:23:03
问题 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

HTML5 Object tag with base64 data content causes Chrome to crash

旧时模样 提交于 2019-12-01 09:14:52
I am using the HTML5 FileReader to read a local file. I then want to immediately display the file contents within the browser, prior to uploading to the server. I read the file, and attempt to display it, as follows: var reader = new FileReader(); reader.onloadend = function () { _moleculefilestream = reader.result; _molecule.filename = filelist[0].name; var filetype = _molecule.filename.substring(_molecule.filename.length - 3); var html = ''; if (filetype == 'jpg' || filetype == 'gif' || filetype == 'png' || filetype == 'tif' || filetype == 'bmp') { html += '<img src="' + reader.result + '" /

How to get progress when uploading file VIA XMLHttpRequest

被刻印的时光 ゝ 提交于 2019-12-01 08:20:43
问题 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 } 回答1: Try xhr.upload.onprogress . In the

FileReader and JSON objects not defined in ie11

十年热恋 提交于 2019-12-01 07:12:59
Whenever trying to open a page running a javascript code using FileReader and JSON upon page initialization, ie11 reports "FileReader is not defined", and later "JSON is not defined". The head of HTML file is as follows: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>LogViewer</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <link rel="stylesheet" href="css/slick.grid.css" type="text/css"/> <link rel="stylesheet" type="text/css" href="css/style.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery

filereader纯前端实现图片预览

倾然丶 夕夏残阳落幕 提交于 2019-12-01 06:57:40
FIleReader,图片预览 FileReader 对象允许 Web 应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据。 实现图片预览功能 。 说明 方法名 参数 描述 abort none 中断读取 readAsBinaryString file 将文件读取为二进制码 readAsDataURL file 将文件读取为 DataURL readAsText file, [encoding] 将文件读取为文本 事件 描述 onabort 中断时触发 onerror 出错时触发 onload 文件读取成功完成时触发 onloadend 读取完成触发,无论成功或失败 onloadstart 读取开始时触发 onprogress 读取中 FileReader.readyState 表示 FileReader 状态的数字,取值如下 0:EMPTY/还没有加载任何数据 1:LOADING/数据正在被加载 2:DONE/已完成全部的读取请求 FileReader.result 文件的内容。该属性仅在读取操作完成后才有效。 FileReader.error 主要使用: FileReader.onload 事件及 FileReader.readAsDataURL() 方法 FileReader.onload 处理

HTML5 Object tag with base64 data content causes Chrome to crash

戏子无情 提交于 2019-12-01 06:34:43
问题 I am using the HTML5 FileReader to read a local file. I then want to immediately display the file contents within the browser, prior to uploading to the server. I read the file, and attempt to display it, as follows: var reader = new FileReader(); reader.onloadend = function () { _moleculefilestream = reader.result; _molecule.filename = filelist[0].name; var filetype = _molecule.filename.substring(_molecule.filename.length - 3); var html = ''; if (filetype == 'jpg' || filetype == 'gif' ||

FileReader losing data when reading PDF

荒凉一梦 提交于 2019-12-01 06:05:22
问题 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

FileReader and JSON objects not defined in ie11

烈酒焚心 提交于 2019-12-01 04:49:10
问题 Whenever trying to open a page running a javascript code using FileReader and JSON upon page initialization, ie11 reports "FileReader is not defined", and later "JSON is not defined". The head of HTML file is as follows: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>LogViewer</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <link rel="stylesheet" href="css/slick.grid.css" type="text/css"/> <link rel="stylesheet" type="text

JS FileReader: Read CSV from Local File & jquery-csv

余生长醉 提交于 2019-12-01 03:36:58
问题 I have a CSV file in the same directory as an html page, and I'd like to use FileReader to read the file contents into a jquery-csv's To Arrays function, but I can't seem to get it to work properly. I think I understand the asynchrony of this task, but have i depicted it correctly? Here, I'm trying to output the 2nd cell in the 2nd column. Thanks for any help. <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages'

Download Excel file from server and save on client

别来无恙 提交于 2019-12-01 00:57:34
问题 I have a JavaScript app and an API that creates a Excel file and returns a byte array with the following headers: Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Content-Disposition:attachment; filename=List.xlsx When I go the Excel resource API URL I'm prompted to download the Excel file. If I do so, it downloads fine and opens in Excel. All is good. Now to the problem: What I don't want is to expose the API URL in the user's browser window, so my goal is to: