Constructors

  • Initialize uploader

    Parameters

    • isPublic: boolean = false

      are we in public mode ?

    • OptionaldestinationFolder: Folder

      the context folder to operate, relative to the root folder

    Returns Uploader

Accessors

  • get customHeaders(): Record<string, string>
  • Get registered custom headers for uploads

    Returns Record<string, string>

  • get destination(): Folder
  • Get the upload destination path relative to the root folder

    Returns Folder

  • set destination(folder): void
  • Set the upload destination path relative to the root folder

    Parameters

    • folder: Folder

    Returns void

Methods

  • Parameters

    • notifier: ((upload: Upload) => void)
        • (upload): void
        • Parameters

          Returns void

    Returns void

  • Uploads multiple files or folders while preserving the relative path (if available)

    Parameters

    • destination: string

      The destination path relative to the root folder. e.g. /foo/bar (a file "a.txt" will be uploaded then to "/foo/bar/a.txt")

    • files: (FileSystemEntry | File)[]

      The files and/or folders to upload

    • Optionalcallback: ((nodes: (File | IDirectory)[], currentPath: string) => Promise<false | (File | IDirectory)[]>)

      Callback that receives the nodes in the current folder and the current path to allow resolving conflicts, all nodes that are returned will be uploaded (if a folder does not exist it will be created)

        • (nodes, currentPath): Promise<false | (File | IDirectory)[]>
        • Parameters

          Returns Promise<false | (File | IDirectory)[]>

    Returns PCancelable<Upload[]>

    Cancelable promise that resolves to an array of uploads

    // For example this is from handling the onchange event of an input[type=file]
    async handleFiles(files: File[]) {
    this.uploads = await this.uploader.batchUpload('uploads', files, this.handleConflicts)
    }

    async handleConflicts(nodes: File[], currentPath: string) {
    const conflicts = getConflicts(nodes, this.fetchContent(currentPath))
    if (conflicts.length === 0) {
    // No conflicts so upload all
    return nodes
    } else {
    // Open the conflict picker to resolve conflicts
    try {
    const { selected, renamed } = await openConflictPicker(currentPath, conflicts, this.fetchContent(currentPath), { recursive: true })
    return [...selected, ...renamed]
    } catch (e) {
    return false
    }
    }
    }
  • Unset a custom header

    Parameters

    • name: string

      The header to unset

    Returns void

  • Set a custom header

    Parameters

    • name: string

      The header to set

    • value: string = ''

      The string value

    Returns void

  • Upload a file to the given path

    Parameters

    • destination: string

      the destination path relative to the root folder. e.g. /foo/bar.txt

    • fileHandle: FileSystemFileEntry | File

      the file to upload

    • Optionalroot: string

      the root folder to upload to

    • retries: number = 5

      number of retries

    Returns PCancelable<Upload>