fileapi

Jcrop 整合 FileAPI 图像裁剪上传

我只是一个虾纸丫 提交于 2019-12-07 03:23:27
Jcrop是一款优秀的jQuery插件,可以非常方便地实现图像裁剪,而且功能十分的强大。 一般的情况下,图像裁剪的实现要经过两次图像上传,第一次将图片上传到后台,后台返回一个链接,通过这个链接在本地实现预览。第二次将图片本身以及裁剪参数上传到后台,后台进行裁剪,并保存在服务器。也就是说第一次的上传是不必要的,用户万一中途取消了操作,那第一次的操作就完全成了无用操作。而且增加了网络的消耗,造成了不必要的浪费。一般这种情况下,我们会考虑第二次不进行上传而使用第一次上传的图片,但这增加了技术难度,而且造成了更多的Exceptions的可能。事实 上有更好的选择,那就是FileAPI,它不进行上传,图片的预览是通过将图片加载到本地浏览器缓存实现的。我们通过FileAPI获取必要的参数,在用户“下定决心”使用该图的时候再进行上传,可以极大的降低多余消耗,增强用户体验。 要实现图像裁剪上传,首先要实现图像本地预览的功能。定义一个priviewImage.js文件,方便复用: function previewImage(file, callback) { /* * file:file控件 prvid: 图片预览容器 */ /*if (file[0].fileSize() > 3 * FileAPI.MB) { alert("The uploading file size must less

Specifying blob encoding in Google Chrome

最后都变了- 提交于 2019-12-06 20:58:12
问题 The following code (vendor normalized) works perfectly fine and displays "➀➁➂ Test" in Firefox 8, but displays "➀âžâž‚ Test" in Google Chrome. Is there any way to preserve encoding of blobs in Google Chrome short of writing a file to a temporary filesystem using the filesystem API? var bb = new BlobBuilder; bb.append("➀➁➂ Test"); var b = bb.getBlob("text/plain;charset=UTF-8"); var url = URL.createObjectURL(b); open(url); 回答1: Gecko (Firefox), WebKit (Safari, Chrome) and Opera support the

traverse through each file in SD card using phonegap file api

两盒软妹~` 提交于 2019-12-06 02:39:57
I want to traverse through each file in the SD card inside all the directories and sub directories using the FILE API of phonegap (which is the w3c file api actually). I have to perform a certain set of operations on these files by looking at their nature. I donot want to search for specific types of files, but traverse through each file in a sequential manner. Can someone please help me with this? Just a basic loop framework with the necessary requirements for the traversal would be a great help. Thank You in advance. I think the following code should work: window.requestFileSystem

download file client-side chunk by chunk

倖福魔咒の 提交于 2019-12-06 02:32:44
问题 I'm using WebRTC to send a file to a connected peer, and I'm sending the file in chunks. However, I'm having trouble figuring out how to get the peer to save/download the file as it is streaming in, chunk by chunk. All the examples I've found online recommend doing something like this: // sender dataConnection.send({ 'file': file }); // receiver dataConnection.on('data', function(fileData) { var dataView = new Uint8Array(fileData); var dataBlob = new Blob([dataView]); var url = window.URL

Fast low-collision non-crypto hash in JavaScript for Files

跟風遠走 提交于 2019-12-06 01:41:23
问题 I am looking for a fast hash with low collisions implemented in JavaScript. It doesn't need to be a crypto hash. I am basically using it as a way to see if a given file has already been uploaded (or partially uploaded) to a user's account to save them some upload time on large (video) files. I am using the new HTML5 File API to read in slices of the file. I then hand this off to SparkMD5 to give me a hash of the file. I like the fact that SparkMD5 allows me to do an incremental hash so I don

how to Preview the video file that user wants to upload on the website (PHP, FiileAPI JS)

橙三吉。 提交于 2019-12-06 01:13:49
I mean, when a user chooses the video file from their system, have the web-page already show them the files they want to upload. I'm already using image file to preview using FileAPI JS. The same I want to do with FileAPI JS for video file. (So, It must be work within my client side) Thanks & answers are appreciated :) You can either use FileReader or createObjectURL . They'll both get the job done, but FileReader has slightly broader support in browsers. createObjectURL will run synchronously and return a Blob URL, a short string referencing the file in memory. and you can free it up

Drag and drop image(s) from desktop to browser instead of searching via input

南笙酒味 提交于 2019-12-05 21:19:50
I'll be honest, way out of my depth here so any help or guidance would be great. I have a very basic input form that allows me to choose multiple images from local folders and display them on the page as well as display info such as file type/name/size. I'd like to be able to drag and drop images into the page, rather than manually search for the images each time. This is where I'm stuck. I have no idea what I need to google to get my desired result. I've seen a lot around the file API that I genuinely don't really understand. Here's what I have so far: https://jsfiddle.net/umx1vpwy/ Any help

Replacement for fileEntry.toURL() in Chrome Packaged Apps

让人想犯罪 __ 提交于 2019-12-05 18:18:20
I'm using the HTML5 FileSystem API in a Chrome Packaged App to write to a log file. I want the user to be able to download this file, so I tried something along the lines of: fs.root.getFile('log.txt', {create: false}, function(fileEntry) { var url = fileEntry.toURL(); // do something with the file url }); This doesn't help though, because the URL is something like filesystem:chrome-extension://eekedjcagggbfigdmifkmhkjbhiklnpj/temporary/log.txt and it's not possible to open it somewhere. What technique would you recommend to make a FileSystem API file in a Packaged App downloadable? Edit:

HTML5 File API modify file.name

陌路散爱 提交于 2019-12-05 18:15:32
I am trying to modify a file's name if something happens. I have tried doing file.name = file.name + 'extra text'; but it doesn't work. How would I go about changing the file's name once it is uploaded? I assume that you are using HTML5 File API to store sandboxed file to local file system. You have to get fileEntry object first if you want to modify an exist file's name: window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs){ fs.root.getFile("targetFileFullName",{},function(fileEntry){ fileEntry.moveTo("original path","newName"); },errorHandler); }, onError); FileEntry

Maximum files of a directory that can be read by FileReader#readEntries in JavaScript

陌路散爱 提交于 2019-12-05 07:54:42
I'm creating a Chrome application. I must read the files of a directory and I am using the DirectoryEntry API and DirectoryReader API . My problem is that the maximum files read using DirectoryReader#readEntries is 100, the first 100 (alphabetical order) var reader = currentDir.createReader(); var read = reader.readEntries.bind(reader, function(files) { for ( var i = 0; i < files.length; i++){ if (files[i].name == nameSearches){ callback(files[i]); } } }) callback(undefined) } read(); The value of files.length is 100 and there are more files in the directory I'm not sure if this limitation is