UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

75 lines 2.99 kB
import { ProgressCallback } from '@/synapse-client/SynapseClient'; import { UploadDestination } from '@sage-bionetworks/synapse-client'; import { UploadFileStatus } from './useTrackFileUploads'; export type UploaderState = 'WAITING' | 'UPLOADING' | 'COMPLETE'; export type BaseFileUploadArgs = { file: File; }; export type BaseFilePreparedForUpload = { file: File; }; export type UploadItem = { file: File; fileHandleId?: string; progress: ProgressCallback; status: UploadFileStatus; cancel: () => void; pause: () => void; resume: () => void; remove: () => void; failureReason?: string; }; export type UseUploadFilesReturn = { /** * The current state of the uploader. */ state: UploaderState; /** * An error message to display if the upload session has failed due to an error. */ errorMessage?: string; /** * The number of files actively being uploaded right now (UPLOADING, PAUSED, or PENDING). */ activeUploadCount: number; /** * List of files being uploaded, with their current progress and status, and callbacks to pause/cancel/resume/remove the upload. */ uploadProgress: UploadItem[]; /** * Arguments used to initialize an upload operation. In addition to providing a file, the caller may also provide * additional information that will be returned when `onUploadComplete` is invoked. */ startUpload: <T extends BaseFilePreparedForUpload = BaseFilePreparedForUpload>(...preparedFiles: T[]) => void; /** * The number of bytes pending upload (including files that are currently uploading, paused, or pending). */ bytesPendingUpload: number; }; export type UseUploadFilesArgs = { /** * Takes precedence over `storageLocationId` if both uploadDestination and storageLocationId are provided. */ uploadDestination?: UploadDestination; /** The ID of the storage location to upload files to */ storageLocationId?: number; /** Optional accessKey for a direct S3 upload */ accessKey?: string; /** Optional secretKey for a direct S3 upload */ secretKey?: string; /** * Callback invoked after a file has been successfully uploaded, with the fileHandleId created for the uploaded file. * @param preparedFile - The prepared file that was passed to `startUpload` * @param fileHandleId - The fileHandleId created for the uploaded file */ onUploadComplete?: <T extends BaseFilePreparedForUpload = BaseFilePreparedForUpload>(preparedFile: T, fileHandleId: string) => Promise<void>; /** * Optional utility that is invoked just before `startUpload` begins uploading files. */ onBeforeUpload?: () => void; }; /** * Hook to start and track the progress of file uploads in Synapse, creating a FileHandle for each uploaded file. */ export declare function useUploadFiles(args?: UseUploadFilesArgs): UseUploadFilesReturn; //# sourceMappingURL=useUploadFiles.d.ts.map