filereader

how to upload image file from url using FileReader API?

放肆的年华 提交于 2019-11-30 02:03:25
问题 In html form, we have a image field, to upload a file. I followed tutorial from http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api and it works fine when uploading a image file from local disk. But suppose i have a image url say http://www.google.com/images/logos/ps_logo2.png and want to upload this image from remote url instead of uploading from local disk. FileReader API works well when trying upload image from local disk but how can we use it to load images by urls?

How to easily process CSV file to List<MyClass>

空扰寡人 提交于 2019-11-29 22:26:06
问题 In my application I use a lot of CSV files which I have to read and build a lists based on them. I'd like to discover an easy way to do this. Do you know any easy framework which does it without using number of config files etc? For instance, I have got a class Person: public class Person { String name; String surname; double shoeSize; boolean sex; // true: male, false:female public Person() { } public String getName() { return name; } public void setName(String name) { this.name = name; }

JS 实现图片上传预览

只愿长相守 提交于 2019-11-29 18:23:28
*/ /*--> */ <body> <div id="preview"></div> <input type="file" onchange="preview(this)" /> <script type="text/javascript"> function preview(file) { var prevDiv = document.getElementById('preview'); if (file.files && file.files[0]) { var reader = new FileReader(); reader.onload = function(evt) { prevDiv.innerHTML = '<img src="' + evt.target.result + '" />'; } reader.readAsDataURL(file.files[0]); } else { prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>'; } } </script> </body> 来源: https:/

Java基础:IO流总结

我的梦境 提交于 2019-11-29 16:22:58
  ------- android培训 、 java培训 、期待与您交流! ---------- IO流在是java中非常重要,也是应用非常频繁的一种技术。初学者要是能把IO技术的学透,java基础也就能更加牢靠。本文是根据以前学习IO的过程中的一些总结,再通过查找资料完善出来的,应该算是比较适合初学者解读的。 一、概念 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象。即数据在两设备间的传输称为流,流的本质是数据传输。所以,为了方便更直观的进行数据操作,就根据数据传输特性将流抽象为各种类。 一个流,必有源端和目的端,它们可以是计算机内存的某些区域,也可以是磁盘文件,甚至可以是Internet上的某个URL。 流的方向是重要的,根据流的方向,流可分为两类:输入流和输出流。用户可以从输入流中读取信息,但不能写它。相反,对输出流,只能往输入流写,而不能读它。 我们可以把形象的比喻成水流 ,文件和程序之间连接一个管道,水流就在之间形成了,自然也就出现了方向:可以流进,也可以流出。 二、流的分类 1.根据从流本身的特点来说,可以分为结点流(nodestream)和过滤流(filters)。 (1)结点流直接从指定的位置(如磁盘文件或内存区域)读或写。(如FileOutputStream和FileInputstream) (2)过滤流输入流往往是以其它输入流作为它的输入源

How to read a local (res/raw) file line by line?

筅森魡賤 提交于 2019-11-29 15:47:26
I have a text file in my res/raw directory. I want to read the file line by line, but FileReader and BufferedReader fail, because of Android's security restriction. How else can I do it? getResources().openRawResource() returns an InputStream that should be usable for line-by-line reading. Joshua A DataInputStream allows you to do a readLine (along with a host of other operations); see DataInputStream Reference . 来源: https://stackoverflow.com/questions/3219150/how-to-read-a-local-res-raw-file-line-by-line

Cordova - Reading Large Image corrupts image

随声附和 提交于 2019-11-29 15:39:45
I am using the image-picker ( cordova-imagePicker ) plugin in order to get images from gallery and upload them to a server. I am using Cordova 6.1.1 with Android platform 5.1.1 and the following plugins: cordova-plugin-camera 2.2.0 "Camera" cordova-plugin-compat 1.0.0 "Compat" cordova-plugin-device 1.0.1 "Device" cordova-plugin-file 4.2.0 "File" cordova-plugin-imagepicker 1.1.0 "ImagePicker" cordova-plugin-inappbrowser 1.4.0 "InAppBrowser" cordova-plugin-media 2.3.0 "Media" As callback to the plugin, I am converting the path I get to a File using the following code. Note that I use resolveFile

How to read a text file into jtextarea in Java Swing

橙三吉。 提交于 2019-11-29 15:27:14
Here is my code: try { String textLine; FileReader fr = new FileReader("ad.txt"); BufferedReader reader = new BufferedReader(fr); while((textLine=reader.readLine()) != null) { textLine = reader.readLine(); jTextArea1.read(reader, "jTextArea1"); } } catch (IOException ioe) { System.err.println(ioe); System.exit(1); } And my .txt file contains the following: contig00001 length=586 numreads=4 CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa ggCCGCGATCCCGTCggaCGGAAAaCGCCcTGGCCCGGGAaCATACCGTTCGGGCCGCCA AGTGTTATAGCCGGACCACTTGTCAGAACATTTCCaaTCCGAAGATGTGAGTtCGGAAGg

base64格式的图片数据如何转成图片

耗尽温柔 提交于 2019-11-29 11:37:31
base64格式的图片数据如何转成图片 一、总结 一句话总结:不仅要去掉前面的格式串,还需要base64_decode()解码才行。 1 // $base_img是获取到前端传递的值 2 $base_img = str_replace('data:image/jpg;base64,', '', $base_img); 3 // 设置文件路径和命名文件名称 4 $path = "./"; 5 $output_file = $prefix.time().rand(100,999).'.jpg'; 6 $path = $path.$output_file; 7 // 创建将数据流文件写入我们创建的文件内容中 8 file_put_contents($path, base64_decode($base_img)); 9 // 输出文件 10 print_r($output_file); 1、base64编码表是怎样的? Base64编码表 码值 字符 码值 字符 码值 字符 码值 字符 0 A 16 Q 32 g 48 w 1 B 17 R 33 h 49 x 2 C 18 S 34 i 50 y 3 D 19 T 35 j 51 z 4 E 20 U 36 k 52 0 5 F 21 V 37 l 53 1 6 G 22 W 38 m 54 2 7 H 23 X 39 n 55 3 8

文件预览或下载中,axios设置responseType:blob时对于后台报错信息的捕获兼容

淺唱寂寞╮ 提交于 2019-11-29 08:50:55
项目中难免会遇到预览文件或者下载文件的场景,如果后台返回的是base64或者图片格式还好说,文件信息直接放在返回body里,作为对象属性给到前端,很直观,也方便取用。 但后台给到的是文件流就要麻烦一些了,一般来说文件流会直接凡在res.data里 处理这种特殊返回值时需要设置axios的responseType为blob,防止axios内部默认处理返回值,导致无法解析: axios.get({ url: 'xxxxxx', method: 'get', data:{}, responseType: 'blob' }).then(res => { console.log(res); }); 当后台解析错误的时候,返回的就是正常的错误对象,包含错误码和错误信息,如果不做处理,那么错误状态和成功状态都是blob类型,无法捕获 但实际上错误状态是这样的形式: 所以需要对返回值做特殊处理,尝试把blob转换为json格式,如果转换成功则说明返回的数据不是文档流,后台出错,反之则文档转换正常,继续下载或预览: axios.get({ url: 'xxxxxx', method: 'get', data:{}, responseType: 'blob' }).then(res => { let data = res.data; let fileReader = new FileReader();

FileReader and CodeMirror Load File Complication

六眼飞鱼酱① 提交于 2019-11-29 07:54:33
Default CodeMirror HTML Editor with Preview - http://jsfiddle.net/D9MvH/1/ - http://liveweave.com/zSqCfA Load File in CodeMirror with FileReader API - http://liveweave.com/VvsXN9 Here's a very simple example of what I'm trying to do. (Save function don't work on these online editors, but the import file function works on this simple editor) - http://liveweave.com/MrUBfZ My problem is when I click my input file form to browse for a file. I choose the HTML document to be opened and it won't open with/in CodeMirror. I tried everything of my knowledge and can't get it to work. Can anyone help with