IAttachmentStore Interface

Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository

Summary

Defines where the AI Assistant keeps the files that users attach to a conversation. Implement it to keep them in storage of your own, such as Azure Blob Storage or Amazon S3.

Syntax

public interface IAttachmentStore

Remarks

Assign an implementation to AttachmentStore of AssistantSettings. When it is null, the repository keeps attached files in its own database. FolderAttachmentStore keeps them in a folder.

The keys are the repository's own: 32 hexadecimal characters. A key is never the user's file name, which the repository keeps only in its own tables. Every server that runs the repository must reach the same store.

When the repository cannot record a file that it has just saved, it calls Delete(..) for the key, so a file that nobody can reach is not left behind.

Methods

  • Delete

    Returns: System.Void

    void Delete(string key)

    Deletes the file stored under the key. A key with no file is not an error.

    Parameters

    • key (System.String) - The key of the file.
  • Open

    Returns: System.IO.Stream - A stream to read the file, or null when no file is stored under the key.

    Stream Open(string key)

    Opens the file stored under the key for reading. The caller disposes the stream.

    Parameters

    • key (System.String) - The key of the file.
  • Save

    Returns: System.Void

    void Save(string key, Stream content)

    Stores a file under the key. Read the stream to its end. The caller disposes it, so do not dispose it yourself.

    Parameters

    • key (System.String) - The key to store the file under.
    • content (System.IO.Stream) - The content of the file.

    Example

      using System.Collections.Concurrent;
      using System.IO;
      using CodeEffects.Rule.Repository;
    
      public class MemoryAttachmentStore : IAttachmentStore
      {
      	private readonly ConcurrentDictionary<string, byte[]> files = new ConcurrentDictionary<string, byte[]>();
    
      	public void Save(string key, Stream content)
      	{
      		using(var buffer = new MemoryStream())
      		{
      			content.CopyTo(buffer);
      			this.files[key] = buffer.ToArray();
      		}
      	}
    
      	public Stream Open(string key)
      	{
      		return this.files.TryGetValue(key, out byte[] bytes) ? new MemoryStream(bytes, false) : null;
      	}
    
      	public void Delete(string key)
      	{
      		this.files.TryRemove(key, out _);
      	}
      }
    

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×