html2app • JS Bridge
    Preparing search index...

    Variable FileSaverConst

    FileSaver: {
        save(
            fileName: string,
            data: string | Blob,
            mimeType?: string,
        ): Promise<MessageResponse<{ saved: boolean; path: string | null }>>;
        saveUrl(
            fileName: string,
            url: string,
            mimeType?: string,
        ): Promise<MessageResponse<{ saved: boolean; path: string | null }>>;
    } = ...

    File saver plugin for saving files to the device.

    Type Declaration

    • save: function
      • Save text or a Blob that was created in JavaScript.

        Parameters

        • fileName: string

          File name with extension, for example notes.txt.

        • data: string | Blob

          Text or a Blob to save.

        • OptionalmimeType: string

          Optional MIME type. Defaults to the Blob type, or text/plain for text.

        Returns Promise<MessageResponse<{ saved: boolean; path: string | null }>>

        saved: true and the saved location if the file was saved, or saved: false if the user cancels the dialog. An error if fileName is empty.

    • saveUrl: function
      • Save a file that is already on the device, given by its localhost URL.

        Only URLs of this server under /_internal/tmp/ are accepted: the URL from a camera, picker or microphone result. Other URLs are rejected, including file:// URLs, remote URLs and paths outside that folder.

        Parameters

        • fileName: string

          File name with extension, for example photo.jpg.

        • url: string

          The localhost URL of the captured file, for example PickedFile.url.

        • OptionalmimeType: string

          Optional MIME type. Defaults to the one from the file name.

        Returns Promise<MessageResponse<{ saved: boolean; path: string | null }>>

        saved: true and the saved location if the file was saved, or saved: false if the user cancels the dialog. An error if the URL is not a captured file on this server.

    Android only for now. Requires the file_saver plugin to be enabled in the app configuration.

    The system save dialog opens, so the user chooses where the file goes. There are two ways to provide the file:

    • FileSaver.save takes text or a Blob created in JavaScript. The data is sent as base64 through the bridge, so use it for small files.
    • FileSaver.saveUrl takes a file that is already on the device, such as PickedFile.url from the camera, a picker or the microphone. The file is read on the native side and is not sent through the bridge. Use it for large files.

    If the user cancels the dialog, the call still succeeds with saved: false.

    import { FileSaver } from '@yandeu/js-bridge/lib/plugins/fileSaver.js'

    await FileSaver.save('notes.txt', 'Hello world')
    await FileSaver.saveUrl('photo.jpg', res.payload.file.url)