fileapi

HTML5 File API simple check if file exists

倾然丶 夕夏残阳落幕 提交于 2019-12-19 07:26:13
问题 I have a temporary File API store (HTML5) but I can't check whether a file exists or not. Is there a simple way to check it? Do I have to actually try and read the file to find out? A search around has yielded me nothing concrete A synchronous check would be nice is this possible? 回答1: You have to read the file. The following example is based on this demo from HTML5Rocks (it catches all errors, you might want to filter the different error types): var errorHandler = function() { // File is not

FileReader API working in jsFiddle, but not from local file

↘锁芯ラ 提交于 2019-12-19 04:13:05
问题 I'm working on a Chrome/Firefox extension which will be using the file API to store files locally. I'm trying to get an example up and running but I'm running into issues which seem to center around Chrome. Can anyone explain why this jsFiddle works fine, but the exact same code, when run from a local file, doesn't work. Please note that it works fine in Firefox, just not in Chrome. Any ideas? 回答1: Chrome has unusually restrictive web security; many things, like Ajax, won't work when run

How to create a File object from binary data in JavaScript

落花浮王杯 提交于 2019-12-19 03:32:44
问题 I'm probably missing something simple here, but how would I create a File object in JavaScript given the binary data as received from an AJAX request? $.ajax({ url: "http://example.com/image.jpg", success: function(data) { // Convert binary data to File object } }); 回答1: I finally figured this out. In order to avoid cross-site scripting issues, I created a proxy endpoint on my server. Then I can pass the image URL to my server, which then executes a GET request on the remote file, converts

HTML5 FIle API: Security Error while reading a file

无人久伴 提交于 2019-12-18 19:46:16
问题 Problem solved, read comment The third problem I have with the HTML5 File API: I still use Chrome 12 on Mac OS X Snow Leopard and I'm still trying to read files with the HTML5 File API, but FileHandler.error() get called because a "SECURITY_ERR" occurres. The file I try to read is a regular .txt file from my desktop, but it neither works with other files although I can open them with regular applications. function FileHandler(files, action) { console.log('FileHandler called.'); this.files =

overwrite a file with HTML5 FileWriter

跟風遠走 提交于 2019-12-18 14:56:05
问题 I'm using HTML5 FileWriter API to save the state of my webapp. I have bit of JS that periodically calls FileWriter.write to do that (so , over time, the write method is called several times). By default FileWriter API use an 'append' approach to writing files which does not suits my needs since I wan't to overwrite the file content. I first tried this: this._writer.seek(0); this._writer.write(content); This is not working when you are writing a text shorter than the file content. I then tried

Decode JPEG2000 bitarray image with Javascript

故事扮演 提交于 2019-12-18 12:21:58
问题 I'm using HTML5 technology with the FileApi. My problem is very simple, but i'm searching since 2 days ago and I have not find anything on the web I have a DicomFile. I use the FileApi from HTML5 to break it down, and get all the information. Finally I get the image data in a byte array. The problem is that I can not decode a JPEG2000 Image and show it in the browser (Chrome, FireFox, any). For example, if the image data is coded in JPEG format, I have no problem at all to show the image in

What and where exactly are privileged code, chrome code, Gecko?

浪尽此生 提交于 2019-12-18 09:38:59
问题 In reading about the File API and wanting to write data directly from an indexedDB database to the client disk instead of first building and holding a large blob in RAM to download to disk, there are a few basic items I'm not understanding. In the MDN documents these two statements are found: In Gecko, privileged code can create File objects representing any local file without user interaction. If you want to use the DOM File API in chrome code, you can do so without restriction. In fact, you

parameter is not of type 'Blob'

北城以北 提交于 2019-12-18 04:35:09
问题 I have written the code below to display the text from a local file using the file API but when I click the button, nothing happens. I get the following error when I inspect the element in the browser. What am I doing wrong? Uncaught TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'. <!DOCTYPE html> <html> <body> <p>This example uses the addEventListener() method to attach a click event to a button.</p> <button id="myBtn">Try it</button> <pre id=

Create multiple input type=“file” elements with their corresponding value (FileList) according to the main input type=“file” (multiple) element

做~自己de王妃 提交于 2019-12-17 21:16:59
问题 I have this code where I loop unto files from a multiple input file type $(function(){ $('#main-input').change(function(){ var files = $('#main-input')[0].files; for (var i = 0, f; f = files[i]; i++) { alert(files[i].name); } }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="file" id="main-input" multiple> What I'm trying to achieve, is clone the main input (#main-input) and gives a value (file) base on the loop files. Any ideas,

Read a local file using JavaScript HTML5 file api (offline website)

核能气质少年 提交于 2019-12-17 16:49:20
问题 I am working on an web site which will be packed in an .exe file. So the site will only be used offline. Now i need to parse an local xml document. How can i get the file handle to a local file using html5 file api? EDIT: I dont want to use <input...> or dragging file into browser. 回答1: I'm afraid I may be the bearer of bad news for your design: The action you are requesting expressly violates the security model as specified in the File API spec. The client implementation of FileReader() must