If you want to trigger the deletion from the database you can do the background job that also is used and deleting media when files are removed with the API.
Create a class in your project as
using System;
using System.Threading.Tasks;
using Litium.Blobs;
using Litium.Scheduler;
namespace Litium.Blobs
{
public class BlobCleanupJob
{
private readonly SchedulerService _schedulerService;
private readonly BlobService _blobService;
public BlobCleanupJob(
BlobService blobService,
SchedulerService schedulerService)
{
_blobService = blobService;
_schedulerService = schedulerService;
}
public Task Cleanup(Uri uri)
{
var container = _blobService.Get(uri);
_blobService.Delete(container);
return Task.CompletedTask;
}
}
}
The sql will be like the following, remember to change the parameters in the first section of the script
DECLARE @fileSystemId UNIQUEIDENTIFIER = '',
@username NVARCHAR(100) = '',
@cleanupJobClassType NVARCHAR(250) = 'Litium.Blobs.BlobCleanupJob, Litium.Application.Mvc'
;
DECLARE @userId UNIQUEIDENTIFIER = (SELECT SystemId FROM Security.PasswordLoginInfo WHERE Id = @username);
INSERT INTO [Scheduler].[ExecutionInfo] (SystemId, DataJson)
SELECT SystemId, '{"arguments":[{"$type":"System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","$value":"' +
BlobUri + '"}],'+
'"declaringType":"' + @cleanupJobClassType + '",'+
'"methodArgumentTypes":["System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"],'+
'"methodName":"Cleanup","currentCulture":"sv-SE","currentUICulture":"en-US","principal":{"authenticationType":"Litium",'+
'"claims":[{"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name","value":"' +
@username + '"},{"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier","value":"' +
CONVERT(NVARCHAR(36), @userId) + '"},{"type":"http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider","value":"Litium Identity"}]}}'
FROM Media.[File] where SystemId = @fileSystemId
;
INSERT INTO [Scheduler].[ScheduledJob] (SystemId, CreatedAtUtc, CreatedBy, QueueAtUtc, [ExecutionInfoSystemId], [ExpireAtUtc])
SELECT NEWID(), GETUTCDATE(), @username, GETUTCDATE(), SystemId, GETUTCDATE() + 100 FROM Media.[file] where SystemId = @fileSystemId
;