/** * The FileTransfer object provides a way to upload files using an HTTP multi-part POST request, * and to download files as well. */ export interface FileTransfer { /** Called with a ProgressEvent whenever a new chunk of data is transferred. */ onprogress: (event: ProgressEvent) => void; /** * Sends a file to a server. * @param fileURL Filesystem URL representing the file on the device. For backwards compatibility, * this can also be the full path of the file on the device. * @param server URL of the server to receive the file, as encoded by encodeURI(). * @param successCallback A callback that is passed a FileUploadResult object. * @param errorCallback A callback that executes if an error occurs retrieving the FileUploadResult. * Invoked with a FileTransferError object. * @param options Optional parameters. * @param trustAllHosts Optional parameter, defaults to false. If set to true, it accepts all security certificates. * This is useful since Android rejects self-signed security certificates. * Not recommended for production use. Supported on Android and iOS. */ upload(fileURL: string, server: string, successCallback: (result: FileUploadResult) => void, errorCallback: (error: FileTransferError) => void, options?: FileUploadOptions, trustAllHosts?: boolean): void; /** * downloads a file from server. * @param source URL of the server to download the file, as encoded by encodeURI(). * @param target Filesystem url representing the file on the device. For backwards compatibility, * this can also be the full path of the file on the device. * @param successCallback A callback that is passed a FileEntry object. (Function) * @param errorCallback A callback that executes if an error occurs when retrieving the fileEntry. * Invoked with a FileTransferError object. * @param options Optional parameters. * @param trustAllHosts Optional parameter, defaults to false. If set to true, it accepts all security certificates. * This is useful since Android rejects self-signed security certificates. * Not recommended for production use. Supported on Android and iOS. */ download(source: string, target: string, successCallback: (fileEntry: FileEntry) => void, errorCallback: (error: FileTransferError) => void, trustAllHosts?: boolean, options?: FileDownloadOptions): void; /** * Aborts an in-progress transfer. The onerror callback is passed a FileTransferError object * which has an error code of FileTransferError.ABORT_ERR. */ abort(): void; } /** A FileUploadResult object is passed to the success callback of the FileTransfer object's upload() method. */ export interface FileUploadResult { /** The number of bytes sent to the server as part of the upload. */ bytesSent: number; /** The HTTP response code returned by the server. */ responseCode: number; /** The HTTP response returned by the server. */ response: string; /** The HTTP response headers by the server. Currently supported on iOS only.*/ headers: unknown; } /** Optional parameters for upload method. */ export interface FileUploadOptions { /** The name of the form element. Defaults to file. */ fileKey?: string; /** The file name to use when saving the file on the server. Defaults to image.jpg. */ fileName?: string; /** The HTTP method to use - either `PUT` or `POST`. Defaults to `POST`. */ httpMethod?: string; /** The mime type of the data to upload. Defaults to image/jpeg. */ mimeType?: string; /** A set of optional key/value pairs to pass in the HTTP request. */ params?: Record; /** Whether to upload the data in chunked streaming mode. Defaults to true. */ chunkedMode?: boolean; /** A map of header name/header values. Use an array to specify more than one value. */ headers?: Record; } /** Optional parameters for download method. */ interface FileDownloadOptions { /** A map of header name/header values. */ headers?: {}; } /** A FileTransferError object is passed to an error callback when an error occurs. */ export interface FileTransferError { /** * One of the predefined error codes listed below. * FileTransferError.FILE_NOT_FOUND_ERR * FileTransferError.INVALID_URL_ERR * FileTransferError.CONNECTION_ERR * FileTransferError.ABORT_ERR * FileTransferError.NOT_MODIFIED_ERR */ code: number; /** URL to the source. */ source: string; /** URL to the target. */ target: string; /** HTTP status code. This attribute is only available when a response code is received from the HTTP connection. */ http_status: number; body: string; exception: unknown; } /** This interface represents a file system. */ interface FileSystem { name: string; /** The root directory of the file system. */ root: DirectoryEntry; } /** * An abstract interface representing entries in a file system, * each of which may be a File or DirectoryEntry. */ export interface Entry { /** Entry is a file. */ isFile: boolean; /** Entry is a directory. */ isDirectory: boolean; /** The name of the entry, excluding the path leading to it. */ name: string; /** The full absolute path from the root to the entry. */ fullPath: string; /** The file system on which the entry resides. */ filesystem: FileSystem; nativeURL: string; /** * Look up metadata about this entry. * @param successCallback A callback that is called with the time of the last modification. * @param errorCallback A callback that is called when errors happen. */ getMetadata(successCallback: (metadata: Metadata) => void, errorCallback?: (error: FileError) => void): void; /** * Move an entry to a different location on the file system. It is an error to try to: * move a directory inside itself or to any child at any depth;move an entry into its parent if a name different from its current one isn't provided; * move a file to a path occupied by a directory; * move a directory to a path occupied by a file; * move any element to a path occupied by a directory which is not empty. * A move of a file on top of an existing file must attempt to delete and replace that file. * A move of a directory on top of an existing empty directory must attempt to delete and replace that directory. * @param parent The directory to which to move the entry. * @param newName The new name of the entry. Defaults to the Entry's current name if unspecified. * @param successCallback A callback that is called with the Entry for the new location. * @param errorCallback A callback that is called when errors happen. */ moveTo(parent: DirectoryEntry, newName?: string, successCallback?: (entry: Entry) => void, errorCallback?: (error: FileError) => void): void; /** * Copy an entry to a different location on the file system. It is an error to try to: * copy a directory inside itself or to any child at any depth; * copy an entry into its parent if a name different from its current one isn't provided; * copy a file to a path occupied by a directory; * copy a directory to a path occupied by a file; * copy any element to a path occupied by a directory which is not empty. * A copy of a file on top of an existing file must attempt to delete and replace that file. * A copy of a directory on top of an existing empty directory must attempt to delete and replace that directory. * Directory copies are always recursive--that is, they copy all contents of the directory. * @param parent The directory to which to move the entry. * @param newName The new name of the entry. Defaults to the Entry's current name if unspecified. * @param successCallback A callback that is called with the Entry for the new object. * @param errorCallback A callback that is called when errors happen. */ copyTo(parent: DirectoryEntry, newName?: string, successCallback?: (entry: Entry) => void, errorCallback?: (error: FileError) => void): void; /** * Returns a URL that can be used as the src attribute of a