<br />

<br />

## Description

Use the `chrome.fileSystem` API to create, read, navigate, and write to the user's local file system. With this API, Chrome Apps can read and write to a user-selected location. For example, a text editor app can use the API to read and write local documents. All failures are notified via chrome.runtime.lastError.

<br />

<br />

## Permissions

`fileSystem`  

<br />

<br />

## Availability

Foreground only

<br />

<br />

<br />

## Types

### AcceptOption

#### Properties

- description string optional

  This is the optional text description for this option. If not present, a description will be automatically generated; typically containing an expanded list of valid extensions (e.g. "text/html" may expand to "\*.html, \*.htm").
- extensions string\[\] optional

  Extensions to accept, e.g. "jpg", "gif", "crx".
- mimeTypes string\[\] optional

  Mime-types to accept, e.g. "image/jpeg" or "audio/\*". One of mimeTypes or extensions must contain at least one valid element.

### ChooseEntryOptions

#### Properties

- accepts [AcceptOption](https://developer.chrome.com/docs/apps/reference/fileSystem#type-AcceptOption)\[\] optional

  The optional list of accept options for this file opener. Each option will be presented as a unique group to the end-user.
- acceptsAllTypes boolean optional

  Whether to accept all file types, in addition to the options specified in the accepts argument. The default is true. If the accepts field is unset or contains no valid entries, this will always be reset to true.
- acceptsMultiple boolean optional

  Whether to accept multiple files. This is only supported for openFile and openWritableFile. The callback to chooseEntry will be called with a list of entries if this is set to true. Otherwise it will be called with a single Entry.
- suggestedName string optional

  The suggested file name that will be presented to the user as the default name to save. This is optional and only applies to 'saveFile'.
- type [ChooseEntryType](https://developer.chrome.com/docs/apps/reference/fileSystem#type-ChooseEntryType) optional

  Type of the prompt to show. The default is 'openFile'.

### ChooseEntryType

#### Enum

"openFile"   
Prompts the user to open an existing file and returns a FileEntry on success. From Chrome 31 onwards, the FileEntry will be writable if the application has the 'write' permission under 'fileSystem'; otherwise, the FileEntry will be read-only.
"openWritableFile"   
Prompts the user to open an existing file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
"saveFile"   
Prompts the user to open an existing file or a new file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
"openDirectory"   
Prompts the user to open a directory and returns a DirectoryEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'directory' permission under 'fileSystem'. If the application has the 'write' permission under 'fileSystem', the returned DirectoryEntry will be writable; otherwise it will be read-only. New in Chrome 31.

<br />

### RequestFileSystemOptions

Chrome 44+

#### Properties

- volumeId string

  The ID of the requested volume.
- writable boolean optional

  Whether the requested file system should be writable. The default is read-only.

### Volume

Chrome 44+

#### Properties

- volumeId string
- writable boolean

### VolumeListChangedEvent

Chrome 44+

#### Properties

- volumes [Volume](https://developer.chrome.com/docs/apps/reference/fileSystem#type-Volume)\[\]

## Methods

### chooseEntry()

```typescript
chrome.fileSystem.chooseEntry(
  options?: ChooseEntryOptions,
  callback: function,
): void
```

Ask the user to choose a file or directory.

#### Parameters

- options [ChooseEntryOptions](https://developer.chrome.com/docs/apps/reference/fileSystem#type-ChooseEntryOptions) optional
- callback function


  The `callback` parameter looks like:

  ```typescript
  (entry?: Entry, fileEntries?: FileEntry[]) => void
  ```

  <br />

  - entry Entry optional
  - fileEntries FileEntry\[\] optional

### getDisplayPath()

Promise

```typescript
chrome.fileSystem.getDisplayPath(
  entry: Entry,
  callback?: function,
): Promise<string>
```

Get the display path of an Entry object. The display path is based on the full path of the file or directory on the local file system, but may be made more readable for display purposes.

#### Parameters

- entry Entry
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (displayPath: string) => void
  ```

  <br />

  - displayPath string

#### Returns

- Promise\<string\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getVolumeList()

Promise Chrome 44+

```typescript
chrome.fileSystem.getVolumeList(
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/fileSystem#type-Volume[] | undefined>
```

Returns a list of volumes available for `requestFileSystem()`. The `"fileSystem": {"requestFileSystem"}` manifest permission is required. Available to kiosk apps running in the kiosk session only. In case of an error, `volumes` will be undefined, and `chrome.runtime.lastError` will be set.

#### Parameters

- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (volumes?: Volume[]) => void
  ```

  <br />

  - volumes [Volume](https://developer.chrome.com/docs/apps/reference/fileSystem#type-Volume)\[\] optional

#### Returns

- Promise\<[Volume](https://developer.chrome.com/docs/apps/reference/fileSystem#type-Volume)\[\] \| undefined\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getWritableEntry()

```typescript
chrome.fileSystem.getWritableEntry(
  entry: Entry,
  callback: function,
): void
```

Get a writable Entry from another Entry. This call will fail with a runtime error if the application does not have the 'write' permission under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if the application does not have the 'directory' permission under 'fileSystem'.

#### Parameters

- entry Entry
- callback function


  The `callback` parameter looks like:

  ```typescript
  (entry: Entry) => void
  ```

  <br />

  - entry Entry

### isRestorable()

Promise

```typescript
chrome.fileSystem.isRestorable(
  id: string,
  callback?: function,
): Promise<boolean>
```

Returns whether the app has permission to restore the entry with the given id.

#### Parameters

- id string
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (isRestorable: boolean) => void
  ```

  <br />

  - isRestorable boolean

#### Returns

- Promise\<boolean\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### isWritableEntry()

Promise

```typescript
chrome.fileSystem.isWritableEntry(
  entry: Entry,
  callback?: function,
): Promise<boolean>
```

Gets whether this Entry is writable or not.

#### Parameters

- entry Entry
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (isWritable: boolean) => void
  ```

  <br />

  - isWritable boolean

#### Returns

- Promise\<boolean\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### requestFileSystem()

Promise Chrome 44+

```typescript
chrome.fileSystem.requestFileSystem(
  options: RequestFileSystemOptions,
  callback?: function,
): Promise<FileSystem | undefined>
```

Requests access to a file system for a volume represented by `options.volumeId`. If `options.writable` is set to true, then the file system will be writable. Otherwise, it will be read-only. The `writable` option requires the `"fileSystem": {"write"}` permission in the manifest. Available to kiosk apps running in kiosk session only. For manual-launch kiosk mode, a confirmation dialog will be shown on top of the active app window. In case of an error, `fileSystem` will be undefined, and `chrome.runtime.lastError` will be set.

#### Parameters

- options [RequestFileSystemOptions](https://developer.chrome.com/docs/apps/reference/fileSystem#type-RequestFileSystemOptions)
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (fileSystem?: FileSystem) => void
  ```

  <br />

  - fileSystem FileSystem optional

#### Returns

- Promise\<FileSystem \| undefined\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### restoreEntry()

```typescript
chrome.fileSystem.restoreEntry(
  id: string,
  callback: function,
): void
```

Returns the file entry with the given id if it can be restored. This call will fail with a runtime error otherwise.

#### Parameters

- id string
- callback function


  The `callback` parameter looks like:

  ```typescript
  (entry: Entry) => void
  ```

  <br />

  - entry Entry

### retainEntry()

```typescript
chrome.fileSystem.retainEntry(
  entry: Entry,
): string
```

Returns an id that can be passed to restoreEntry to regain access to a given file entry. Only the 500 most recently used entries are retained, where calls to retainEntry and restoreEntry count as use. If the app has the 'retainEntries' permission under 'fileSystem', entries are retained indefinitely. Otherwise, entries are retained only while the app is running and across restarts.

#### Parameters

- entry Entry

#### Returns

- string

## Events

### onVolumeListChanged

Chrome 44+

```typescript
chrome.fileSystem.onVolumeListChanged.addListener(
  callback: function,
)
```

Called when a list of available volumes is changed.

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (event: VolumeListChangedEvent) => void
  ```

  <br />

  - event [VolumeListChangedEvent](https://developer.chrome.com/docs/apps/reference/fileSystem#type-VolumeListChangedEvent)

<br />