Git Product home page Git Product logo

fileapi's Introduction

File API Specification

This repository is for editing drafts and discussion of the File API specification.

This spec was started with W3C's CVS repository but usage of that repository has stopped.

fileapi's People

Contributors

afbarstow avatar annevk avatar astorije avatar autokagami avatar ctavan avatar customcommander avatar dlrobertson avatar domenic avatar foolip avatar inexorabletash avatar izgzhen avatar johanna-hub avatar johannhof avatar jugglinmike avatar jungkees avatar lucacasonato avatar manishearth avatar marcoscaceres avatar mkruisselbrink avatar ms2ger avatar plehegar avatar rwlbuis avatar saschanaz avatar sideshowbarker avatar siusin avatar tabatkins avatar timothygu avatar vsesh avatar wh0 avatar ylafon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fileapi's Issues

"origin of a blob URL" is redundant/confusing

The origin of a Blob URL
must be the same as the origin specified by the incumbent settings object at the time the method that created it was called.

This is stated as a normative statement, implying to me that blob URL's have some special origin that must be set at creation time.

However, the origin of a blob URL is instead normatively determined via the URL Standard. So this is just a statement of fact about what happens to be true according to the below algorithm, which is what creates blob URLs.

So it should be changed to a statement of fact, instead of a "must":

The origin of a Blob URL will be the same as the origin specified by the incumbent settings object at the time the method that created it was called.

Furthermore, this would be much clearer if instead of defining the new term "origin of a Blob URL", it just linked the first "origin" in this sentence to https://url.spec.whatwg.org/#concept-url-origin

Implementations allow all values in type getter

The following code:

a = new Blob([1,2,3], {type: "text/(plain"});
console.log(a.type) // prints text/(plain

works in Chrome and Firefox. It also works if you replace ( with \x02 or something

The spec, however, asks user agents to restrict values in the range U+0020 to U+007E in the constructor, and in the getter it only allows a nonempty value to be returned if it is a parseable MIME type.

Perhaps we should relax these restrictions in the spec?

Re-add FileReader.readAsBinaryString() ?

Stats in Chrome: https://www.chromestatus.com/metrics/feature/timeline/popularity/814

Hovering around 0.0008% which is low. But an HTTPArchive search turned up thousands of uses; spot-checking, it's not just one library but several different uses. The method is implemented in Edge, FF, Chrome and Safari.

So... is it worth continuing to try and drop it from implementations, or should we just accept it as a wart on FileReader, document, and move on?

(As an aside, cribbing text() and arrayBuffer() from Body to Blob would be awesome...)

Add FileList constructor

Split out from https://www.w3.org/Bugs/Public/show_bug.cgi?id=17125 :

The

<input type="file" name="something" />

element has always been readonly (you can't change value) for security purposes.
That makes sense as a string could always be manipulated by JS.

The File object on the other hand should be "safe", as in

  • Only the browser can create one on user request (ie. by file input or drag and drop)
  • JS cannot change it in any way

So it should not be a security issue to allow assignment to a file input.
For example:

<input type="file" name="something[]" onchange="splitFiles();" id="in1" multiple="multiple" />
function splitFiles() {
  var in = document.getElementById('in1');
  //create single inputs
  for(var i=0;i<in.files.length;i++) {
        var newEl = document.createElement('input');
        newEl.name = "something[]";
        newEl.id = '...';
        newEl.type = "file";
        newEl.value = in.files[i]; // <-- assignment of file object
        document.appendChild(newEl); //add for upload
        //create some UI to remove this input
        //...
    }
    //remove the multi-input
    in.parent.removeChild(in);
}

This code would split a multi-file-input back to multiple single-file inputs (that way applications with a legacy backend that only supports the classical way could also support multi-file-inputs).

Another use would be with File objects obtained by drag and drop.
Right now those require XHR to upload. Allowing to make them a selection of a file input could simplify some situations as well as provide richer UI (when showing a traditional file input together with a drop area those would stay in sync).

Fix Blob Origin

This issue is to fix Blob URL's origin, based largely on bugs filed on HTML.

Currently, File API has this:

"The origin of a Blob URL must be the same as the effective script origin specified by the incumbent settings object at the time the method that created it -- either URL.createObjectURL or URL.createFor -- was called."

This should be much better.

Use "index.html" as the filename of the spec.

A common practice when the gh-pages (branch) is used, is to name the main file "index.html". Unless there's a good reason to keep with "Overview.html", please use "index.html" instead.

Use `optional` for the Blob constructor

Currently, the spec has (boring parts omitted):

[Constructor, Constructor(sequence<...> blobParts, optional BlobPropertyBag options)] 
interface Blob {

It would probably be better to use

[Constructor(optional sequence<...> blobParts, optional BlobPropertyBag options)] 
interface Blob {

Note that this handles

new Blob(undefined)

differently: the current spec throws a TypeError; after the change, it would be equivalent to new Blob().

CC @bzbarsky

.msg MimeType Not Recognized

It appears that in certain instances the FileAPI is not recognizing the MIME type for .msg (Microsoft Outlook) files. This is a worldwide standard no different from a .jpg or .png file so why would it not be recognized. Specifically we are using the RadAsyncUpload control from Telerik which I understand is built upon the File API but the content type (Mime Type) for those files is not being passed back via the control presumably because the FileAPI is not recognizing it. Added the Mime type to local registry or IIS server has no effect. Please provide guidance and/or fix.

Persistent blob urls

Update: See https://gist.github.com/petkaantonov/37a9c64ea2bbd1aa3ca5

Currently blob urls don't persist between browser restarts / page refreshes etc so the user has to add same files to the app over and over again everytime the app is started.

For certain kinds of apps it is necessary to be able to create a persistent blob url. For instance a media player app that has access to the media files the user has added to the app so they don't have to keep readding the files (possibly thousands) every time the app is started. Duplicating copies of the files in FileSystem or IndexedDB is out of the question as this duplicates possibly gigabytes of data which takes a long time, wastes a lot of storage and hits limits quickly.

Reading

I suggest a method like URL.createPersistentObjectUrl is added. The url is valid as long as the original file exists in exactly same location with exactly same attributes and contents as they were when the URL was created. When the file is modified, moved or altered in any way, the url should become invalid (perhaps URL.isPersistentUrlValid can be used to check it?). This can be probably done just by checking the last modified attribute.

Writing

One could also be allowed to write to a valid persistent object urls by sending binary data as a POST request to the url. However, every time such a POST request is made, the browser should prompt the user for confirmation that "the app wants to modify the flie at [path], is this ok?". Also such requests should probably only be allowed to made in response to user event like click. After successful write, the browser should update the persistent object url to match the new file attributes and contents that were updated.

Security considerations

As far as I can see, this should not give the app access to any more information than existing APIs already give.

Controlling Blob URL's

Hi. I have several HTML5 apps I work on, all of which allow users to save files locally. I can't seem to figure out how to control the URL so the users aren't downloading files with gibberish names, or how to force the browser to open a Save As dialog.

Anyway, any help would be greatly appreciated.

Remove parsable mime type requirement?

In the definition for the type attribute, the spec has:

The ASCII-encoded string in lower case representing the media type of the Blob. On getting, user agents must return the type of a Blob as an ASCII-encoded string in lower case, such that when it is converted to a byte sequence, it is a parsable MIME type [MIMESNIFF], or the empty string -- 0 bytes -- if the type cannot be determined.

There's a fair bit weird about that paragraph (e.g. 'ASCII-encoded' when the entry points which set the type already reject non-ASCII input, referring to the length of the string in bytes...). But neither Chrome nor Firefox appear to do the filtering of non-parsable MIME types:

new Blob(['yo'], {type: "te?xt/plain"}).type; // "te?xt/plain"

Even if we decide to keep the spec and file/fix implementation bugs, can we rejigger the spec so that the entry points that set type (constructors, slice()) do all of the filtering work, rather than spreading it across two parts of the spec? (Unless there's subtlety I'm missing...)

cc: @annevk @Ms2ger

Bikeshedding the spec

In my fork, I'm converting the spec to the Bikeshed processor. The current generated file is pretty inaccurate in several places - it's clear that the ToC has drifted from the actual sections over time, for example.

  • Initial conversion pass
  • Fix link failures (properly linking to out-of-document things)
  • Fix relevant Bikeshed bugs (uncovered during conversion of DOM)

Just letting y'all know, so you don't spend too much time working directly on the index.html file, or putting the effort into ReSpeccing it. I expect this to be finished in a week, as some of the bugs the DOM conversion uncovered (which this spec is also hitting) require some decent refactoring work I'll be doing over the next several days.

Add a FileList.drop(index) method

Migrating my own request https://www.w3.org/Bugs/Public/show_bug.cgi?id=17125 :

Currently a FileList provided by a file input element is readonly.

This is problematic if the user added multiple files to a file list and then sees that he included one file too much and want's to remove it before uploading the files. Right now he has to start his selection from scratch.

If there was a way to drop items from a FileList some JavaScript could display a list of selected files and allow to remove items one-by-one.

Duplicate https://www.w3.org/Bugs/Public/show_bug.cgi?id=16834 adds another use case:

  • Checking the file.size for some limit before uploading, if limit is exceeded exclude the particular file from uploading.

#24 discusses an alternative approach, fitting a wider range of use cases.

Blob.close() has several problems

Not defined what happens with b in

a = new Blob(...)
b = new Blob([a])
a.close()

Probably it should not be closed.

We need to define how this affects other specifications such as FormData, XMLHttpRequest, etc.

If blob.close() revokes URLs it needs to be defined how that happens. Are the URLs stored on the instance?

Document BlobPropertyBag "endings", or keep pushing to remove?

https://jsfiddle.net/422r7n3z/ - exercises new Blob([s], {endings:e}).size

On Windows, in Chrome/Firefox:
transparent + "abc\r\n" = 5
transparent + "abc\n" = 4
transparent + "abc\r" = 4
native + "abc\r\n" = 5
native + "abc\n" = 5
native + "abc\r" = 5

On Windows, in IE11:
transparent + "abc\r\n" = 5
transparent + "abc\n" = 4
transparent + "abc\r" = 4
native + "abc\r\n" = 5
native + "abc\n" = 4
native + "abc\r" = 4

On OSX and Linux, in Chrome/Firefox/Safari:
transparent + "abc\r\n" = 5
transparent + "abc\n" = 4
transparent + "abc\r" = 4
native + "abc\r\n" = 4
native + "abc\n" = 4
native + "abc\r" = 4

(I have not tested Opera or Edge; I assume those match Chrome and IE11)

Note that all 4 browsers - including IE which does not appear to respect the option otherwise - throw if an invalid option is passed as endings.

I gathered usage stats in Chrome stable: https://www.chromestatus.com/metrics/feature/timeline/popularity/1320 - it's 0% to several significant figures (people running web-platform-tests would account for the absolute #s).

Should we proceed with removing, or does anyone want to advocate for keeping it? @smaug----, @foolip, @aliams, .... ?

Use ASCII origin in blob URLs

URLs are typically ASCII in final form. Creating URLs that are not ASCII in final form is bad news and would require ugly decoding and such.

file selection dialog callable by file api

It seems, that file select dialog called by INPUT tag with type "file" is not working, because in current browser solutions this functionality cannot be invoked by code properly. The current default behaviour of this tag type is secured by explicit user clicking.

I would appreciate to get file select functions in this api, maybe a fileselect object to set all properties of fileselect dialog (type open/save, filename, mimes, flags (multiselect/single select) and so on and a show function.

Re-word the way the various read operations are defined

In particular the way the description of the result attribute sort of defines how the result of a read operation is represented is sub-optimal. Some more explicit steps to transform the body returned by the read operation to the various types might make sense.

What does it mean to invoke the Blob constructor with zero parameters?

For example, what should this do:

var b = new Blob(undefined, { type: "foo" });

? Should b.type be empty string or "foo"? In any case, there is no concept of "number of parameters" for IDL implementation algorithms, so please define the behavior in terms of concepts that do exist.

Standardize extension to content type mapping?

(This discussion could go here or HTML — which notes "Extensions tend to be ambiguous..." — but I'm guessing the right eyeballs will be here.)

When a File is minted via a drop operation or HTMLInputElement in Chrome, the content type is determined using platform-specific logic. e.g. on Windows the registry is used as is normal for the platform. There's also a small fallback list built into the browser. This causes behavior to differ for the same version of Chrome on the same OS depending on what applications are installed (e.g. .DOCX may be unknown if Office is not installed). Presumably this is also an interop issue across browsers on the same machine if different logic/lists are used is used.

Web applications should trust neither extensions nor content types. But should we attempt to standardize the behavior here in any way, e.g. an expected list of extension → type mappings, to avoid developer surprise?

I'm not strongly advocating for this, just wanted to kick off the discussion.

Streams are hot, FileReader.readAs____ is not

Large Blob/Files becomes an issue if you don't slice it into chunks...

Streams brings other cool feature like pipe-ing, back pressure & transforming
Currently I'm using Response (part of Fetch) to transform a blob to a stream that i can "read into" step by step

var stream = new Response(blob).body
var reader = stream.getReader()

This works okey. but it feels hacky.
Could we get new method to get a stream from File & Blob's please?

Constructing a new blob from a closed blob

Currently it seems that the spec allows to create a new blob starting from a closed one:

var a = new Blob([42]);
a.close();
var b = new Blob([a]);

This seems wrong to me because a.size is 0 and that blob cannot be read in any way.
I would suggest to throw an exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.