diff --git a/files/en-us/web/api/file/file/index.md b/files/en-us/web/api/file/file/index.md index 448a55cde90576c..e3e99da4601350c 100644 --- a/files/en-us/web/api/file/file/index.md +++ b/files/en-us/web/api/file/file/index.md @@ -6,7 +6,7 @@ page-type: web-api-constructor browser-compat: api.File.File --- -{{APIRef("File")}} +{{APIRef("File API")}}{{AvailableInWorkers}} The **`File()`** constructor creates a new {{domxref("File")}} object instance. @@ -14,29 +14,34 @@ object instance. ## Syntax ```js-nolint -new File(bits, name) -new File(bits, name, options) +new File(fileBits, fileName) +new File(fileBits, fileName, options) ``` ### Parameters -- `bits` +- `fileBits` - : An [iterable](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) object such as an {{jsxref("Array")}}, having {{jsxref("ArrayBuffer")}}s, {{jsxref("TypedArray")}}s, {{jsxref("DataView")}}s, {{domxref("Blob")}}s, strings, or a mix of any of such elements, that will be put inside the {{domxref("File")}}. Note that strings here are encoded as UTF-8, unlike the usual JavaScript UTF-16 strings. -- `name` +- `fileName` - : A string representing the file name or the path to the file. - `options` {{optional_inline}} - : An options object containing optional attributes for the file. Available options are as follows: - - `type` + - `type` {{optional_inline}} - : A string representing the MIME type of the content that will be put into the file. Defaults to a value of `""`. - - `lastModified` + - `endings` {{optional_inline}} + - : How to interpret newline characters (`\n`) within the contents, if + the data is text. The default value, `transparent`, copies newline + characters into the blob without changing them. To convert newlines to the host + system's native convention, specify the value `native`. + - `lastModified` {{optional_inline}} - : A number representing the number of milliseconds between the Unix time epoch and when the file was last modified. Defaults to a value of {{jsxref("Date.now()")}}. diff --git a/files/en-us/web/api/file/index.md b/files/en-us/web/api/file/index.md index f2b8a58e53c7416..c0204bc6d95a0fc 100644 --- a/files/en-us/web/api/file/index.md +++ b/files/en-us/web/api/file/index.md @@ -5,7 +5,7 @@ page-type: web-api-interface browser-compat: api.File --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} The **`File`** interface provides information about files and allows JavaScript in a web page to access their content. @@ -24,6 +24,8 @@ See [Using files from web applications](/en-US/docs/Web/API/File_API/Using_files ## Instance properties +_The `File` interface also inherits properties from the {{DOMxRef("Blob")}} interface._ + - {{DOMxRef("File.lastModified")}} {{ReadOnlyInline}} - : Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight). - {{DOMxRef("File.lastModifiedDate")}} {{Deprecated_Inline}} {{ReadOnlyInline}} {{Non-standard_Inline}} @@ -33,25 +35,9 @@ See [Using files from web applications](/en-US/docs/Web/API/File_API/Using_files - {{DOMxRef("File.webkitRelativePath")}} {{ReadOnlyInline}} - : Returns the path the URL of the {{DOMxRef("File")}} is relative to. -`File` implements {{DOMxRef("Blob")}}, so it also has the following properties available to it: - -- {{DOMxRef("Blob.size")}} {{ReadOnlyInline}} - - : Returns the size of the file in bytes. -- {{DOMxRef("Blob.type")}} {{ReadOnlyInline}} - - : Returns the [MIME](/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type of the file. - ## Instance methods -_The `File` interface doesn't define any methods, but inherits methods from the {{DOMxRef("Blob")}} interface:_ - -- {{DOMxRef("Blob.slice()")}} - - : Returns a new `Blob` object containing the data in the specified range of bytes of the source `Blob`. -- {{DOMxRef("Blob.stream()")}} - - : Transforms the `File` into a {{DOMxRef("ReadableStream")}} that can be used to read the `File` contents. -- {{DOMxRef("Blob.text()")}} - - : Transforms the `File` into a stream and reads it to completion. It returns a promise that resolves with a string (text). -- {{DOMxRef("Blob.arrayBuffer()")}} - - : Transforms the `File` into a stream and reads it to completion. It returns a promise that resolves with an {{jsxref("ArrayBuffer")}}. +_The `File` interface also inherits methods from the {{DOMxRef("Blob")}} interface._ ## Specifications diff --git a/files/en-us/web/api/file/lastmodified/index.md b/files/en-us/web/api/file/lastmodified/index.md index 7c58a2ca35457ae..cf415232c2f8161 100644 --- a/files/en-us/web/api/file/lastmodified/index.md +++ b/files/en-us/web/api/file/lastmodified/index.md @@ -6,9 +6,9 @@ page-type: web-api-instance-property browser-compat: api.File.lastModified --- -{{APIRef("File")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -The **`File.lastModified`** read-only property provides the +The **`lastModified`** read-only property of the {{domxref("File")}} interface provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date. @@ -80,7 +80,7 @@ console.log(fileWithoutDate.lastModified); // returns current time ## Reduced time precision -To offer protection against timing attacks and [fingerprinting](/en-US/docs/Glossary/Fingerprinting), the precision of +To offer protection against timing attacks and {{glossary("fingerprinting")}}, the precision of `someFile.lastModified` might get rounded depending on browser settings. In Firefox, the `privacy.reduceTimerPrecision` preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms. diff --git a/files/en-us/web/api/file/lastmodifieddate/index.md b/files/en-us/web/api/file/lastmodifieddate/index.md index 7fb1679e5afd3c4..c9a82f625f70b6b 100644 --- a/files/en-us/web/api/file/lastmodifieddate/index.md +++ b/files/en-us/web/api/file/lastmodifieddate/index.md @@ -9,9 +9,9 @@ status: browser-compat: api.File.lastModifiedDate --- -{{APIRef("File API")}}{{Deprecated_Header}}{{Non-standard_Header}} +{{APIRef("File API")}}{{AvailableInWorkers}}{{Deprecated_Header}}{{Non-standard_Header}} -The **`File.lastModifiedDate`** read-only property returns the last modified date of the file. Files without a known last modified date return the current date. +The **`lastModifiedDate`** read-only property of the {{domxref("File")}} interface returns the last modified date of the file. Files without a known last modified date return the current date. ## Value @@ -32,7 +32,7 @@ for (const file of fileInput.files) { ## Reduced time precision -To offer protection against timing attacks and [fingerprinting](/en-US/docs/Glossary/Fingerprinting), the precision of `someFile.lastModifiedDate.getTime()` might get rounded depending on browser settings. +To offer protection against timing attacks and {{glossary("fingerprinting")}}, the precision of `someFile.lastModifiedDate.getTime()` might get rounded depending on browser settings. In Firefox, the `privacy.reduceTimerPrecision` preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms. diff --git a/files/en-us/web/api/file/name/index.md b/files/en-us/web/api/file/name/index.md index 710f7f86296f5fc..eeb7e1f4879a369 100644 --- a/files/en-us/web/api/file/name/index.md +++ b/files/en-us/web/api/file/name/index.md @@ -6,9 +6,9 @@ page-type: web-api-instance-property browser-compat: api.File.name --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -Returns the name of the file represented by a {{domxref("File")}} object. For security +The **`name`** read-only property of the {{domxref("File")}} interface returns the name of the file represented by a {{domxref("File")}} object. For security reasons, the path is excluded from this property. ## Value diff --git a/files/en-us/web/api/file/webkitrelativepath/index.md b/files/en-us/web/api/file/webkitrelativepath/index.md index 643e68eddbae7ff..a32657eaaacd803 100644 --- a/files/en-us/web/api/file/webkitrelativepath/index.md +++ b/files/en-us/web/api/file/webkitrelativepath/index.md @@ -6,9 +6,9 @@ page-type: web-api-instance-property browser-compat: api.File.webkitRelativePath --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -The **`File.webkitRelativePath`** is a read-only property that +The **`webkitRelativePath`** read-only property of the {{domxref("File")}} interface contains a string which specifies the file's path relative to the directory selected by the user in an {{HTMLElement("input")}} element with its [`webkitdirectory`](/en-US/docs/Web/HTML/Element/input#webkitdirectory) attribute set. diff --git a/files/en-us/web/api/filelist/index.md b/files/en-us/web/api/filelist/index.md index c1c23a94475eace..856de9dd3d8313e 100644 --- a/files/en-us/web/api/filelist/index.md +++ b/files/en-us/web/api/filelist/index.md @@ -5,9 +5,9 @@ page-type: web-api-interface browser-compat: api.FileList --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -An object of this type is returned by the `files` property of the HTML {{HTMLElement("input")}} element; this lets you access the list of files selected with the `` element. It's also used for a list of files dropped into web content when using the drag and drop API; see the [`DataTransfer`](/en-US/docs/Web/API/DataTransfer) object for details on this usage. +The **`FileList`** interface represents an object of this type returned by the `files` property of the HTML {{HTMLElement("input")}} element; this lets you access the list of files selected with the `` element. It's also used for a list of files dropped into web content when using the drag and drop API; see the {{domxref("DataTransfer")}} object for details on this usage. All `` element nodes have a `files` attribute of type `FileList` on them which allows access to the items in this list. For example, if the HTML includes the following file input: @@ -15,7 +15,7 @@ All `` element nodes have a `files` attribute of type `FileList` on them ``` -The following line of code fetches the first file in the node's file list as a [`File`](/en-US/docs/Web/API/File) object: +The following line of code fetches the first file in the node's file list as a {{domxref("File")}} object: ```js const file = document.getElementById("fileItem").files[0]; @@ -25,12 +25,12 @@ const file = document.getElementById("fileItem").files[0]; ## Instance properties -- {{DOMxRef("FileList/length", "length")}} {{ReadOnlyInline}} +- {{DOMxRef("FileList.length", "length")}} {{ReadOnlyInline}} - : A read-only value indicating the number of files in the list. ## Instance methods -- {{DOMxRef("FileList/item", "item()")}} {{ReadOnlyInline}} +- {{DOMxRef("FileList.item()", "item()")}} - : Returns a {{domxref("File")}} object representing the file at the specified index in the file list. ## Example @@ -84,5 +84,5 @@ fileInput.addEventListener("change", () => { ## See also - [Using files from web applications](/en-US/docs/Web/API/File_API/Using_files_from_web_applications) -- [`File`](/en-US/docs/Web/API/File) -- [`FileReader`](/en-US/docs/Web/API/FileReader) +- {{domxref("File")}} +- {{domxref("FileReader")}} diff --git a/files/en-us/web/api/filelist/item/index.md b/files/en-us/web/api/filelist/item/index.md index a9c7280755d0fe2..876b5a399bff415 100644 --- a/files/en-us/web/api/filelist/item/index.md +++ b/files/en-us/web/api/filelist/item/index.md @@ -6,9 +6,9 @@ page-type: web-api-instance-method browser-compat: api.FileList.item --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -The **`item()`** method of the {{domxref("FileList")}} API returns a {{domxref("File")}} object representing the file at the specified index in the file list. +The **`item()`** method of the {{domxref("FileList")}} interface returns a {{domxref("File")}} object representing the file at the specified index in the file list. ## Syntax @@ -23,7 +23,7 @@ item(index) ### Return value -A [`File`](/en-US/docs/Web/API/File) object representing the requested file. +A {{domxref("File")}} object representing the requested file. ## Examples diff --git a/files/en-us/web/api/filelist/length/index.md b/files/en-us/web/api/filelist/length/index.md index 7ca3d474b387080..4e0a760a31b0373 100644 --- a/files/en-us/web/api/filelist/length/index.md +++ b/files/en-us/web/api/filelist/length/index.md @@ -6,9 +6,9 @@ page-type: web-api-instance-property browser-compat: api.FileList.length --- -{{APIRef("File API")}} +{{APIRef("File API")}}{{AvailableInWorkers}} -The read-only {{domxref("FileList")}} **`length`** property returns the number of files in the `FileList`. +The **`length`** read-only property of the {{domxref("FileList")}} interface returns the number of files in the `FileList`. ## Value