pub fn copy(
ctx: &Ctx,
from: &str,
to: &str,
) -> impl Future<Output = Result<Option<u64>>> + Send + use<>Expand description
Copies the object at from to to inside the bucket (content type kept) and returns its size, or None when from does not exist.
The bytes stream from R2 to R2 through the Worker without being held in
memory. Objects up to 5 GiB are one PUT; larger ones are copied in
parts of 1 GiB (a 10 GB file: 10 parts, about 20 subrequests). An
object already at to is replaced.
Free plan: one class B operation per read (one per part) and one class A operation per write (plus the create and complete of a multipart copy).
§Errors
Error::Internal (500) when the STORAGE
binding is missing or R2 fails (a multipart copy is aborted then).
§Examples
use ocre::{Ctx, Result, storage};
// Keeps a copy of a reported file before its owner can delete it.
async fn preserve(ctx: &Ctx, key: &str, report_id: i64) -> Result<bool> {
Ok(storage::copy(ctx, key, &format!("evidence/{report_id}")).await?.is_some())
}