Skip to content

Commit c676b48

Browse files
feat(upload): emit event on file upload start (#462)
1 parent 2ba482e commit c676b48

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/lib/api/upload/upload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class Upload extends EventEmitter {
131131

132132
this.uploader.setUploadTags(options.tags);
133133

134+
this.uploader.on('start', () => this.emit('start'));
134135
this.uploader.on('error', (e) => this.emit('error', e));
135136
this.uploader.on('progress', this.handleProgress.bind(this));
136137
}

src/lib/api/upload/uploaders/s3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export class S3Uploader extends UploaderAbstract {
364364
);
365365

366366
debug(`[${id}] All tasks for %s enqueued. Start processing main upload queue`, id);
367+
this.emit('start');
367368
this.partsQueue.start();
368369

369370
resolve(await this.partsQueue.onIdle());

src/lib/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ export class Client extends EventEmitter {
457457
upload.setSecurity(security);
458458
}
459459

460+
upload.on('start', () => this.emit('upload.start'));
460461
/* istanbul ignore next */
461462
upload.on('error', e => {
462463
if (this.forwardErrors) {
@@ -522,6 +523,7 @@ export class Client extends EventEmitter {
522523
upload.setSecurity(security);
523524
}
524525

526+
upload.on('start', () => this.emit('upload.start'));
525527
/* istanbul ignore next */
526528
upload.on('error', e => {
527529
Sentry.withScope(scope => {

src/lib/picker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ export interface PickerResponse {
172172
export interface PickerFileCallback {
173173
(file: PickerFileMetadata): void | Promise<any>;
174174
}
175+
export interface PickerFileWithTokenCallback {
176+
(file: PickerFileMetadata, token?: {pause?: () => void, resume?: () => void, cancel?: () => void}): void | Promise<any>;
177+
}
175178

176179
export interface PickerFileCancelCallback {
177180
(file: PickerFileMetadata): void;
@@ -624,7 +627,7 @@ export interface PickerOptions {
624627
/**
625628
* Called when a file begins uploading.
626629
*/
627-
onFileUploadStarted?: PickerFileCallback;
630+
onFileUploadStarted?: PickerFileWithTokenCallback;
628631
/**
629632
* Called when a file is done uploading.
630633
*/

0 commit comments

Comments
 (0)