code: func (s *storageImpl) CancelUpload(c context.Context, r *api.CancelUploadRequest) (resp *api.UploadOperation, err error) {
  	defer func() { err = grpcutil.GRPCifyAndLogErr(c, err) }()
  
  	handleOpStatus := func(op *upload.Operation) (*api.UploadOperation, error) {
  		if op.Status == api.UploadStatus_ERRORED || op.Status == api.UploadStatus_CANCELED {
  			return op.ToProto(r.UploadOperationId), nil
  		}
  		return nil, errors.Reason("the operation is in state %s and can't be canceled", op.Status).Tag(grpcutil.FailedPreconditionTag).Err()
  	}
  
  	// Grab the corresponding operation and inspect its status.
  	op, err := fetchOp(c, r.UploadOperationId)
  	switch {
  	case err != nil:
  		return nil, err
  	case op.Status != api.UploadStatus_UPLOADING:
  		return handleOpStatus(op)
  	}
  
  	// Move the operation to canceled state and launch the TQ task to cleanup.
  	mutated, err := op.Advance(c, func(c context.Context, op *upload.Operation) error {
  		op.Status = api.UploadStatus_CANCELED
  		return s.tq.AddTask(c, &tq.Task{
  			Payload: &tasks.CleanupUpload{
  				UploadOperationId: op.ID,
  				UploadUrl:         op.UploadURL,
  				PathToCleanup:     op.TempGSPath,
  			},
  			Title: fmt.Sprintf("%d", op.ID),
  		})
  	})
  	if err != nil {
  		return nil, errors.Annotate(err, "failed to start the cleanup task").
  			Tag(grpcutil.InternalTag).Err()
  	}
  	return handleOpStatus(mutated)
  }
docs: // CancelUpload implements the corresponding RPC method, see the proto doc.