S-Drive 3.6 Documentation

cancelUpload ()

Abandons an in-progress upload by deleting its Work In Progress (WIP) Salesforce record — and, by default, whatever bytes already exist at that file's storage key too.

Use it when an upload you started with initializeUpload never finished (the client-side upload failed, the user navigated away, the connection dropped, etc.) and you don't want the WIP record sitting around indefinitely.

For canceling a multipart upload, you need to call abortMutliPartUpload and/or deleteMultiParts first, and then call cancelUpload. See Canceling an Upload for details.

How to call this method

global static List<ResultObject> cancelUpload(List<Id> wipIds, String objectId)

global static List<ResultObject> cancelUpload(List<Id> wipIds, String objectId, Boolean isDeleteS3Object)

The first overload always deletes the underlying storage object along with the WIP record. The second lets you keep the stored bytes and remove only the Salesforce record, if for some reason you want that.

Parameters

Parameter

Type

Required

Description

wipIds

List<Id>

Yes

The WIP file record Id(s) to cancel — the wipFileId values from the UploadRequestInfo that initializeUpload returned for the upload(s) you're abandoning.

objectId

String

Yes

The Id of the parent record the file(s) were being uploaded to (e.g. the Account or Case Id, or a folder Id) — not the WIP record's own Id.

isDeleteS3Object

Boolean

No — defaults to true on the 2-parameter overload

Whether to also delete whatever's at the file's storage key. Left true in virtually every real cancellation, since the point is usually to remove the abandoned upload completely.

Return value

Returns List<ResultObject>, one entry per Id in wipIds, in the same order:

Field

Description

status

'success' or 'fail'

errorMessage

Populated when status == 'fail'

Check every status — a partial failure across several cancelled uploads doesn't throw, it just reports 'fail' for the ones that didn't clean up.

⚠ Before you call this

  • Avoid calling this more than once in the same transaction. With isDeleteS3Object = true, each call does both a callout (deleting the storage object) and a DML delete (removing the WIP record) — and once any DML has happened in a transaction, Salesforce blocks a further callout until you commit. Looping over several parents and calling cancelUpload once per parent, synchronously, in one transaction will fail on the second call with System.CalloutException: You have uncommitted work pending. Give each call its own transaction (e.g. a Queueable per group) if you need to cancel more than one upload's worth of work.

Example

// Client-side upload failed after initializeUpload created the WIP record — clean it up.
List<ResultObject> results = SDriveTools.cancelUpload(
    new List<Id>{ info.wipFileId },
    caseId
);

for (ResultObject r : results) {
    if (r.status == 'fail') {
        System.debug(LoggingLevel.ERROR, 'Failed to cancel upload: ' + r.errorMessage);
    }
}