content disposition

This commit is contained in:
2025-11-02 02:26:40 +01:00
parent b9c95437d2
commit b561f46d2c
6 changed files with 53 additions and 48 deletions
+27 -9
View File
@@ -20,7 +20,12 @@ pub trait ObjectStorage: Send + Sync + 'static {
content_disposition: Option<String>,
) -> Result<()>;
async fn presign_get_object(&self, key: &str, expires_in: Duration) -> Result<String>;
async fn presign_get_object(
&self,
key: &str,
expires_in: Duration,
response_content_disposition: Option<&str>,
) -> Result<String>;
async fn get_object(&self, key: &str) -> Result<Vec<u8>>;
@@ -73,17 +78,23 @@ impl ObjectStorage for S3Storage {
Ok(())
}
async fn presign_get_object(&self, key: &str, expires_in: Duration) -> Result<String> {
async fn presign_get_object(
&self,
key: &str,
expires_in: Duration,
response_content_disposition: Option<&str>,
) -> Result<String> {
let presign_config = PresigningConfig::builder()
.expires_in(expires_in)
.build()
.context("failed to build S3 presigning config")?;
let presigned = self
.client
.get_object()
.bucket(&self.bucket)
.key(key)
let mut request = self.client.get_object().bucket(&self.bucket).key(key);
if let Some(value) = response_content_disposition {
request = request.response_content_disposition(value);
}
let presigned = request
.presigned(presign_config)
.await
.context("failed to generate presigned download URL")?;
@@ -157,9 +168,16 @@ impl TenantStorage {
.await
}
pub async fn presign_get_object(&self, key: &str, expires_in: Duration) -> Result<String> {
pub async fn presign_get_object(
&self,
key: &str,
expires_in: Duration,
response_content_disposition: Option<&str>,
) -> Result<String> {
let qualified = self.qualify(key);
self.inner.presign_get_object(&qualified, expires_in).await
self.inner
.presign_get_object(&qualified, expires_in, response_content_disposition)
.await
}
pub async fn get_object(&self, key: &str) -> Result<Vec<u8>> {