Page 1 of 1

File API .text() is not supported

Posted: 2021-06-06, 23:47
by Lurker_01
Using https://developer.mozilla.org/en-US/docs/Web/API/FileList
Specific function https://developer.mozilla.org/en-US/docs/Web/API/Blob/text
Working Draft: https://w3c.github.io/FileAPI/#dom-blob-text

Code: Select all

domElem.files[i].text()
Is not supported.
While it is possible to use a file reader as an alternative, in some cases .text() is easier to work with, see function Usage notes.
Firefox 69 implementation bug #1557121, bug #1577311
This makes impossible for a website to read the uploaded data without storage, ej: web game reading imported save file, not using clipboard paste.
To reproduce you could use File List example and use .text() instead of .name under the alert.

Edit: Moved to Browser Development from Web Site compatibility since it is a more relevant board

Re: File API .text() is not supported

Posted: 2021-06-07, 00:42
by Moonchild
Use FileReader.readAsText()
It has the advantage of being widely supported by all browsers and is event-based (meaning you're actually using the native paradigm for JS) as well as being able to use encodings other than UTF-8 if necessary.

Re: File API .text() is not supported

Posted: 2021-06-07, 01:09
by Lurker_01
Moonchild wrote:
2021-06-07, 00:42
Use FileReader.readAsText()
Lurker_01 wrote:
2021-06-06, 23:47
While it is possible to use a file reader as an alternative...
Like i said, yes this is a workaround. i was talking with the game developers and said that this API is a Working draft, and that they could use File Reader instead of this shortcut but they treated it as a "browser bug".
This is outside of my control and i am just reporting a problem.

Re: File API .text() is not supported

Posted: 2021-06-07, 01:24
by Moonchild
Well we can't do anything about something that isn't a browser bug, no matter if they call it that.
It's already bad enough that we have to implement working draft specs to begin with, let alone ones that have well-supported alternatives that do the exact same thing. The only thing they'd have to do is use the event handler for loaded state instead of a promise (and they can even wrap it in a promise in JS too if they have some aversion to using it as-is, shimming the API).

So the solution is simple: they can either use a broadly-supported API instead of their draft shiny, or lose players.