Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface UploadOptions {
onError?: (error: Error | DetailedError) => void
onShouldRetry?: (error: DetailedError, retryAttempt: number, options: UploadOptions) => boolean
onUploadUrlAvailable?: () => void | Promise<void>
onShouldRemoveFromUrlStorage?: () => boolean | Promise<boolean>

overridePatchMethod: boolean
headers: { [key: string]: string }
Expand Down
9 changes: 9 additions & 0 deletions lib/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const defaultOptions = {
onSuccess: undefined,
onError: undefined,
onUploadUrlAvailable: undefined,
onShouldRemove: undefined,

overridePatchMethod: false,
headers: {},
Expand Down Expand Up @@ -938,12 +939,20 @@ export class BaseUpload {

/**
* Remove the entry in the URL storage, if it has been saved before.
* If the `onShouldRemoveFromUrlStorage` option is provided and is a function,
* it will be invoked to determine whether the removal should proceed.
* If it returns or resolves to `false`, the removal is skipped.
*
* @api private
*/
private async _removeFromUrlStorage(): Promise<void> {
if (!this._urlStorageKey) return

if (typeof this.options.onShouldRemoveFromUrlStorage === 'function') {
const shouldRemove = await Promise.resolve(this.options.onShouldRemoveFromUrlStorage())
if (!shouldRemove) return
}

await this.options.urlStorage.removeUpload(this._urlStorageKey)
this._urlStorageKey = undefined
}
Expand Down
Loading