public override bool SetBlobStream(Stream stream, Guid blobId, CallContext context) { Assert.ArgumentNotNull(stream, "stream"); Assert.ArgumentNotNull(context, "context"); if (!_externalBlobStorageProviderConfigured) { return(base.SetBlobStream(stream, blobId, context)); } lock (_blobSetLocks.GetLock(blobId)) { try { _blobStorageProvider.Put(stream, blobId.ToString()); // Note: We should insert an empty reference to the BlobId into the SQL Blobs table, this is basically to assist with the cleanup process. // During cleanup, it's faster to query the database for the blobs that should be removed as opposed to retrieving and parsing a list from Azure. string cmdText = " INSERT INTO [Blobs]( [Id], [BlobId], [Index], [Created], [Data] ) VALUES( NewId(), @blobId, @index, @created, @data)"; using (var connection = new SqlConnection(Api.ConnectionString)) { connection.Open(); var command = new SqlCommand(cmdText, connection) { CommandTimeout = (int)CommandTimeout.TotalSeconds }; command.Parameters.AddWithValue("@blobId", blobId); command.Parameters.AddWithValue("@index", 0); command.Parameters.AddWithValue("@created", DateTime.UtcNow); command.Parameters.Add("@data", SqlDbType.Image, 0).Value = new byte[0]; command.ExecuteNonQuery(); } } catch (StorageException ex) { Log.Error($"AzureStorage: Upload of blob with Id {blobId} failed.", ex, this); throw; } } return(true); }