Skip to main content

complete_multipart

Function complete_multipart 

Source
pub fn complete_multipart(
    ctx: &Ctx,
    key: &str,
    upload_id: &str,
    parts: &[CompletedPart],
) -> impl Future<Output = Result<bool>> + Send + use<>
Expand description

Assembles the multipart upload upload_id of key from parts; false when the upload no longer exists.

parts are every part, in order, with the ETag R2 answered (quoted or not): the uploader’s report, or list_parts mapped with StoredPart::completed. The object exists once this returns true. false means the upload was completed (perhaps by a concurrent call: check the object with head), aborted, or expired.

Free plan: one R2 class A operation.

§Errors

Error::BadRequest (400) when R2 refuses the parts (a missing part, a wrong ETag, a part under 5 MiB but the last); Error::Internal when the STORAGE binding is missing.

§Examples

use ocre::{Ctx, Result, storage};

// The worker said it is done: assemble whatever parts it stored.
async fn finish(ctx: &Ctx, key: &str, upload_id: &str) -> Result<bool> {
    let Some(parts) = storage::list_parts(ctx, key, upload_id).await? else {
        return storage::exists(ctx, key).await; // completed already
    };
    let parts: Vec<_> = parts.iter().map(storage::StoredPart::completed).collect();
    storage::complete_multipart(ctx, key, upload_id, &parts).await
}