Browser / Web Api - File (Blob)

About

A file in the Javascript Browser Api (WebApi) is represented by a File object 1).

The file object is a blob object that adds support for files on the user's system.

Management

Creation

Input file

When you use a HTML input of file type to select files, you get back a file object. See How to handle files in Javascript with the File API of the Browser?

Demo:

<input type="file" accept=".txt"/>
  • The input object gives access to the files selected via the the files property that holds a FileList 2) a list of file
document.querySelector("input").addEventListener('change', async  (event) => {
    let file = event.target.files[0];
    console.log(`File name: ${file.name}`);
    let text = await (new Response(file)).text();
    console.log(text);
});
  • Result: Choose a text file, the file name and content will be printed below

Reference





Discover More
Blob Url In Browser Address
Browser / Javascript - Object URL (createObjectURL / revokeObjectURL)

An ObjectUrl is the representation of blob object as a data URL strings that can be used with any fetch HTML element that accepts an URL as an attribute. HTML Example: This HTML was generated with...
Html Input File Multiple Warning Dialog
How to handle files in Javascript with the File API of the Browser?

The file api is a browser javascript api that allows file system operation in the browser. FileApiopeneditsave Uploading a file: You can open and read files via the input of type file The...
Html Input File Multiple Warning Dialog
How to work with an Input File in an HTML form?

The input file is an input of type file that permits to select files or directory and send them to the browser file system api HTML HTML The HTML Result from the operating system: This...



Share this page:
Follow us:
Task Runner