Welcome What's new in Chrome extensions Getting started API Reference Samples
Welcome What's new in Chrome extensions Getting started API Reference Samples

chrome.syncFileSystem

This API is part of the deprecated Chrome Apps platform. Learn more about migrating your app.
  • Description

    Use the chrome.syncFileSystem API to save and synchronize data on Google Drive. This API is NOT for accessing arbitrary user docs stored in Google Drive. It provides app-specific syncable storage for offline and caching usage so that the same data can be available across different clients. Read Manage Data for more on using this API.

  • Permissions
    syncFileSystem

Summary

Types

ConflictResolutionPolicy

Enum

"last_write_win", or "manual"

FileInfo

Properties

  • action
    SyncAction optional

    Sync action taken to fire onFileStatusChanged event. The action value can be 'added', 'updated' or 'deleted'. Only applies if status is 'synced'.

  • direction
    SyncDirection optional

    Sync direction for the onFileStatusChanged event. Sync direction value can be 'local_to_remote' or 'remote_to_local'. Only applies if status is 'synced'.

  • fileEntry
    Entry

    fileEntry for the target file whose status has changed. Contains name and path information of synchronized file. On file deletion, fileEntry information will still be available but file will no longer exist.

  • Resulting file status after onFileStatusChanged event. The status value can be 'synced', 'pending' or 'conflicting'.

FileStatus

Enum

"synced", "pending", or "conflicting"

FileStatusInfo

Properties

  • error
    string optional

    Optional error that is only returned if there was a problem retrieving the FileStatus for the given file.

  • fileEntry
    Entry

    One of the Entry's originally given to getFileStatuses.

  • The status value can be 'synced', 'pending' or 'conflicting'.

ServiceInfo

Properties

ServiceStatus

Enum

"initializing", "running", "authentication_required", "temporary_unavailable", or "disabled"

StorageInfo

Properties

  • quotaBytes
    number
  • usageBytes
    number

SyncAction

Enum

"added", "updated", or "deleted"

SyncDirection

Enum

"local_to_remote", or "remote_to_local"

Methods

getConflictResolutionPolicy

getConflictResolutionPolicy(callback: function): void

Gets the current conflict resolution policy.

Parameters

getFileStatus

getFileStatus(fileEntry: Entry, callback: function): void

Returns the FileStatus for the given fileEntry. The status value can be 'synced', 'pending' or 'conflicting'. Note that 'conflicting' state only happens when the service's conflict resolution policy is set to 'manual'.

Parameters

  • fileEntry
    Entry
  • callback
    function

    A callback type for getFileStatus.

    The parameter should be a function that looks like this:

    (status: FileStatus) => {...}

getFileStatuses

getFileStatuses(fileEntries: object[], callback: function): void

Returns each FileStatus for the given fileEntry array. Typically called with the result from dirReader.readEntries().

Parameters

  • fileEntries
    object[]
  • callback
    function

    A callback type for getFileStatuses.

    The parameter should be a function that looks like this:

    (status: FileStatusInfo[]) => {...}

getServiceStatus

getServiceStatus(callback: function): void

Returns the current sync backend status.

Parameters

  • callback
    function

    A callback type for getServiceStatus.

    The parameter should be a function that looks like this:

    (status: ServiceStatus) => {...}

getUsageAndQuota

getUsageAndQuota(fileSystem: DOMFileSystem, callback: function): void

Returns the current usage and quota in bytes for the 'syncable' file storage for the app.

Parameters

  • fileSystem
    DOMFileSystem
  • callback
    function

    A callback type for getUsageAndQuota.

    The parameter should be a function that looks like this:

    (info: StorageInfo) => {...}

requestFileSystem

requestFileSystem(callback: function): void

Returns a syncable filesystem backed by Google Drive. The returned DOMFileSystem instance can be operated on in the same way as the Temporary and Persistant file systems (see http://dev.w3.org/2009/dap/file-system/file-dir-sys.html).

Calling this multiple times from the same app will return the same handle to the same file system.

Note this call can fail. For example, if the user is not signed in to Chrome or if there is no network operation. To handle these errors it is important chrome.runtime.lastError is checked in the callback.

Parameters

  • callback
    function

    A callback type for requestFileSystem.

    The parameter should be a function that looks like this:

    (fileSystem: DOMFileSystem) => {...}
    • fileSystem
      DOMFileSystem

setConflictResolutionPolicy

setConflictResolutionPolicy(policy: ConflictResolutionPolicy, callback?: function): void

Sets the default conflict resolution policy for the 'syncable' file storage for the app. By default it is set to 'last_write_win'. When conflict resolution policy is set to 'last_write_win' conflicts for existing files are automatically resolved next time the file is updated. callback can be optionally given to know if the request has succeeded or not.

Parameters

  • callback
    function optional

    A generic result callback to indicate success or failure.

    If you specify the parameter, it should be a function that looks like this:

    () => {...}

Events

onFileStatusChanged

onFileStatusChanged.addListener(listener: function)

Fired when a file has been updated by the background sync service.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (detail: FileInfo) => {...}

onServiceStatusChanged

onServiceStatusChanged.addListener(listener: function)

Fired when an error or other status change has happened in the sync backend (for example, when the sync is temporarily disabled due to network or authentication error).

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (detail: ServiceInfo) => {...}
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.