feat: add post3 s3 proxy for postgresql
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
78
crates/post3-sdk/examples/metadata.rs
Normal file
78
crates/post3-sdk/examples/metadata.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
//! Demonstrate custom metadata (x-amz-meta-*) with post3.
|
||||
//!
|
||||
//! Prerequisites: post3-server running on localhost:9000
|
||||
//! mise run up && mise run dev
|
||||
//!
|
||||
//! Run:
|
||||
//! cargo run -p post3-sdk --example metadata
|
||||
|
||||
use post3_sdk::Post3Client;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let endpoint = std::env::var("POST3_ENDPOINT")
|
||||
.unwrap_or_else(|_| "http://localhost:9000".to_string());
|
||||
let client = Post3Client::new(&endpoint);
|
||||
|
||||
client.create_bucket("meta-bucket").await?;
|
||||
|
||||
// Use the inner aws-sdk-s3 client to set custom metadata
|
||||
let inner = client.inner();
|
||||
println!("Putting object with custom metadata...");
|
||||
inner
|
||||
.put_object()
|
||||
.bucket("meta-bucket")
|
||||
.key("report.pdf")
|
||||
.body(Vec::from(&b"fake pdf content"[..]).into())
|
||||
.content_type("application/pdf")
|
||||
.metadata("author", "alice")
|
||||
.metadata("department", "engineering")
|
||||
.metadata("version", "2")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
// Retrieve metadata via head_object
|
||||
let head = inner
|
||||
.head_object()
|
||||
.bucket("meta-bucket")
|
||||
.key("report.pdf")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
println!("Content-Type: {:?}", head.content_type());
|
||||
println!("Content-Length: {:?}", head.content_length());
|
||||
println!("ETag: {:?}", head.e_tag());
|
||||
if let Some(metadata) = head.metadata() {
|
||||
println!("Custom metadata:");
|
||||
for (k, v) in metadata {
|
||||
println!(" x-amz-meta-{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the full object with metadata
|
||||
let resp = inner
|
||||
.get_object()
|
||||
.bucket("meta-bucket")
|
||||
.key("report.pdf")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
println!("\nGet object response:");
|
||||
println!(" Content-Type: {:?}", resp.content_type());
|
||||
if let Some(metadata) = resp.metadata() {
|
||||
println!(" Metadata:");
|
||||
for (k, v) in metadata {
|
||||
println!(" x-amz-meta-{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
|
||||
let body = resp.body.collect().await?.into_bytes();
|
||||
println!(" Body: {}", String::from_utf8_lossy(&body));
|
||||
|
||||
// Cleanup
|
||||
client.delete_object("meta-bucket", "report.pdf").await?;
|
||||
client.delete_bucket("meta-bucket").await?;
|
||||
println!("\nDone!");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user