Expand description
Storage for document bodies (Binary content, attachments, exports) that is independent of the hosting cloud.
Callers only use the DocumentStorage trait; each backend lives under
providers behind a cargo feature and is built with connect.
Every call names the tenant and project the document belongs to
(DocumentScope) and the document’s name within them (DocumentName),
so a caller can only ever reach its own project’s documents.
use haste_document_storage::{
Document, DocumentName, DocumentScope, DocumentStorageKind,
providers::gcs::{GcsConfig, GcsCredentials},
};
use haste_jwt::{ProjectId, TenantId};
let storage = haste_document_storage::connect(DocumentStorageKind::Gcs(GcsConfig {
bucket: "my-bucket".into(),
prefix: Some("documents".into()),
credentials: GcsCredentials::ApplicationDefault,
endpoint: None,
}))
.await?;
let scope = DocumentScope::new(
&TenantId::new("acme".to_string())?,
&ProjectId::new("clinic".to_string())?,
);
let name = DocumentName::new("Binary/123")?;
storage
.put(
&scope,
&name,
Document::new(b"...".as_slice()).with_content_type("application/pdf"),
)
.await?;
let document = storage.get(&scope, &name).await?;
let bytes = document.body.collect().await?;Modules§
Structs§
- Document
- A document to store: its bytes and what the backend keeps with them.
- Document
Body - A document body as a stream of chunks. Forward it chunk by chunk (for
example into an HTTP response) or gather it with
DocumentBody::collect. - Document
Metadata - What a backend knows about a stored document without reading its body.
- Document
Name - A document’s name within its
DocumentScope, such asBinary/123. - Document
Scope - The tenant and project a document belongs to.
- List
Page - One page of a scope’s listing, in name order.
- List
Request - Selects one page of a scope’s listing.
- Stored
Document - A stored document: its metadata and body.
Enums§
- Document
Storage Kind - The backend to connect to, with its configuration.
- Storage
Error - Failure of a
DocumentStoragecall.
Traits§
- Document
Storage - Object storage for document bodies. A document is addressed by the
DocumentScope(tenant and project) it belongs to and itsDocumentNamewithin that scope.
Functions§
- connect
- Builds the configured backend and verifies that it can authenticate. The
Postgres backend’s table must already exist (see
providers::postgres).
Type Aliases§
- Storage
Future - Boxed future returned by
DocumentStoragemethods, so the trait stays object safe.