fileapi

Blob from DataURL?

我的梦境 提交于 2019-11-26 11:16:06
Using FileReader 's readAsDataURL() I can transform arbitrary data into a Data URL. Is there way to convert a Data URL back into a Blob instance using builtin browser apis? devnull69 User Matt has proposed the following code a year ago ( How to convert dataURL to file object in javascript? ) which might help you EDIT: As some commenters reported, BlobBuilder has been deprecated some time ago. This is the updated code: function dataURItoBlob(dataURI) { // convert base64 to raw binary data held in a string // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this var

How to get a file or blob from an object URL?

我怕爱的太早我们不能终老 提交于 2019-11-26 10:16:13
I am allowing the user to load images into a page via drag&drop and other methods. When an image is dropped, I'm using URL.createObjectURL to convert to an object URL to display the image. I am not revoking the url, as I do reuse it. So, when it comes time to create a FormData object so I can allow them to upload a form with one of those images in it, is there some way I can then reverse that Object URL back into a Blob or File so I can then append it to a FormData object? As gengkev alludes to in his comment above, it looks like the best/only way to do this is with an async xhr2 call: var xhr

Adding UTF-8 BOM to string/Blob

ぃ、小莉子 提交于 2019-11-26 09:27:56
问题 I need to add a UTF-8 byte-order-mark to generated text data on client side. How do I do that? Using new Blob([\'\\xEF\\xBB\\xBF\' + content]) yields \'\"my data\"\' , of course. Neither did \'\\uBBEF\\x22BF\' work (with \'\\x22\' == \'\"\' being the next character in content ). Is it possible to prepend the UTF-8 BOM in JavaScript to a generated text? Yes, I really do need the UTF-8 BOM in this case. 回答1: Prepend \ufeff to the string. See http://msdn.microsoft.com/en-us/library/ie

Getting Image Dimensions using Javascript File API

我与影子孤独终老i 提交于 2019-11-26 07:23:50
问题 I require to generate a thumbnail of an image in my Web Application. I make use of the Html 5 File API to generate the thumbnail. I made use of the examples from the below URL to generate the thumbnails. http://www.html5rocks.com/en/tutorials/file/dndfiles/ I am successfully able to generate the thumbnails. The problem that I have is I am able to generate thumbnail only by using a static size. Is there a way to get the file dimensions from the selected file and then create the Image object?

How FileReader.readAsText in HTML5 File API works?

时光毁灭记忆、已成空白 提交于 2019-11-26 04:55:29
问题 I wrote the following code to check whether the uploaded file exists or not using HTML5 file API. <input type=\"file\" id=\"myfile\"> <button type=\"button\" onclick=\"addDoc()\">Add Document</button> <p id=\"DisplayText\"></p> The following JavaScript code has been mapped to it is as follows: function addDoc() { var file=document.getElementById(\"myFile\").files[0]; //for input type=file var reader=new FileReader(); reader.onload = function(e) {} reader.readAsText(file); var error = reader

Getting byte array through input type = file

安稳与你 提交于 2019-11-26 04:47:39
问题 var profileImage = fileInputInByteArray; $.ajax({ url: \'abc.com/\', type: \'POST\', dataType: \'json\', data: { // Other data ProfileImage: profileimage // Other data }, success: { } }) // Code in WebAPI [HttpPost] public HttpResponseMessage UpdateProfile([FromUri]UpdateProfileModel response) { //... return response; } public class UpdateProfileModel { // ... public byte[] ProfileImage {get ;set; } // ... } <input type=\"file\" id=\"inputFile\" /> I am using ajax call to post byte[] value of

Remember and Repopulate File Input [duplicate]

落花浮王杯 提交于 2019-11-26 03:20:18
问题 This question already has an answer here : How to set file input value when dropping file on page? [duplicate] (1 answer) Closed last year . Note: The answer(s) below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element via JavaScript in 2017. See the answer in this question for details as well as a demo: How to set file input value programatically (i.e.: when drag-dropping files)? I have a website that allows the user to upload a file

How to upload and list directories at firefox and chrome/chromium using change and drop events

人盡茶涼 提交于 2019-11-26 02:21:09
Both mozilla and webkit browsers now allow directory upload. When directory or directories are selected at <input type="file"> element or dropped at an element, how to list all directories and files in the order which they appear in actual directory at both firefox and chrome/chromium, and perform tasks on files when all uploaded directories have been iterated? You can set webkitdirectory and allowdirs attributes at <input type="file"> element; attach change , drop events to <input type="file"> element; use .getFilesAndDirectories() at mozilla, .createReader() , .readEntries() at webkit ,

Blob from DataURL?

混江龙づ霸主 提交于 2019-11-26 02:08:43
问题 Using FileReader \'s readAsDataURL() I can transform arbitrary data into a Data URL. Is there way to convert a Data URL back into a Blob instance using builtin browser apis? 回答1: User Matt has proposed the following code a year ago ( How to convert dataURL to file object in javascript? ) which might help you EDIT: As some commenters reported, BlobBuilder has been deprecated some time ago. This is the updated code: function dataURItoBlob(dataURI) { // convert base64 to raw binary data held in

How to download a file without using <a> element with download attribute or a server?

那年仲夏 提交于 2019-11-26 02:03:49
问题 According to caniuse the download attribute of <a> element is supported at Microsoft Edge build 10547+, but not IE or Safari. How to download a file object without using <a> element with download attribute set or a server? 回答1: There are a number of ways of triggering a download. Following are a few: Use a form: <form method="get" action="mydoc.doc"> <button type="submit">Download</button> </form> Use javascript: <button type="submit" onclick="window.open('mydoc.doc')">Download</button> 回答2: