Skip to main content

presign_put

Function presign_put 

Source
pub fn presign_put(
    ctx: &Ctx,
    key: &str,
    content_type: &str,
    size: u64,
    expires_in: u64,
) -> Result<String>
Expand description

Presigns a PUT of exactly size bytes of type content_type at key, valid expires_in seconds.

The URL signs Content-Type (normalized) and Content-Length: R2 refuses a PUT with another type or size. For browser uploads prefer direct_upload, which also picks a new key, checks Rules and signs the key for attach_direct_upload. Settings, costs and errors as presign_get; the upload is one class A operation.

ยงExamples

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

// A URL a backup script can `curl -T` to, valid one hour.
fn backup_url(ctx: &Ctx, size: u64) -> Result<String> {
    storage::presign_put(ctx, "backups/latest.tar", "application/x-tar", size, 3600)
}