Complete documentation of metadata added to uploaded files.
r2put automatically adds metadata to all uploaded files. This metadata is set on the R2 object and can be retrieved via the R2 API.
uploaded-atISO 8601 timestamp indicating when the file was uploaded.
"2024-01-15T13:53:05.123Z"original-filenameOriginal filename from the upload.
--key if provided--file path"data.bin" or "images/hero.png"interface UploadMetadata {
'uploaded-at': string; // ISO 8601 timestamp
'original-filename': string; // Original filename from --key argument (or --file path if --key not provided)
}Metadata is automatically added to all uploaded files:
The original-filename field is determined as follows:
If --key is provided: Uses the value from --key
r2put --file ./local-image.png --bucket assets --key images/hero.png
# original-filename: "images/hero.png"If --key is not provided: Uses filename from --file path
r2put --file ./data.bin --bucket my-bucket
# original-filename: "data.bin"The uploaded-at timestamp:
"2024-01-15T13:53:05.123Z"Metadata is not displayed in the terminal UI output. To retrieve metadata:
import { R2 } from '@cfkit/r2';
const r2 = new R2({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
accessKeyId: process.env.R2_ACCESS_KEY_ID!,
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
});
const object = await r2.headObject({
bucket: 'my-bucket',
key: 'data.bin',
});
console.log(object.metadata);
// {
// 'uploaded-at': '2024-01-15T13:53:05.123Z',
// 'original-filename': 'data.bin'
// }r2put --file ./data.bin --bucket my-bucketMetadata:
uploaded-at: "2024-01-15T13:53:05.123Z" (example)original-filename: "data.bin"r2put --file ./local-image.png --bucket assets --key images/hero.pngMetadata:
uploaded-at: "2024-01-15T13:53:05.123Z" (example)original-filename: "images/hero.png"r2put --file /home/user/documents/file.pdf --bucket my-bucketMetadata:
uploaded-at: "2024-01-15T13:53:05.123Z" (example)original-filename: "file.pdf" (filename only, not full path)Use uploaded-at to:
Use original-filename to:
uploaded-at and original-filename@cfkit/r2 directly for custom metadataSymptoms:
Resolution:
uploaded-at and original-filenameSymptoms:
original-filename doesn't match expected valueResolution:
--key provided, original-filename uses --key value--key not provided, original-filename uses filename from --file path