Cloudflare R2 icon

Cloudflare R2

Store and retrieve objects from Cloudflare R2

Overview

This node integrates with Cloudflare R2, a scalable object storage service compatible with the S3 API. Specifically, the "Object" resource's "List" operation allows users to list objects stored within a specified R2 bucket. This is useful for retrieving metadata about stored files, such as their keys (paths), sizes, and modification dates.

Common scenarios include:

  • Enumerating all files in a bucket to process or analyze them.
  • Filtering objects by prefix to find files within a specific folder or namespace.
  • Limiting the number of returned objects for pagination or performance reasons.

Practical example:

  • A user wants to list all images stored under the prefix "photos/2024/" in their R2 bucket named "my-media-bucket", limiting the results to 500 objects per request.

Properties

Name Meaning
Bucket Name The name of the Cloudflare R2 bucket from which to list objects.
Options Additional options to filter and limit the listing:
- Prefix Limits the response to keys that begin with this specified prefix (e.g., folder path).
- Max Keys The maximum number of keys (objects) to return in the response; maximum allowed is 1000.

Output

The output JSON contains details about the listed objects in the bucket, including:

  • name: The bucket name.
  • objects: An array of objects, each representing an item in the bucket with properties such as:
    • Key: The object's key (path).
    • LastModified: Timestamp of last modification.
    • ETag: Entity tag for the object.
    • Size: Size of the object in bytes.
    • StorageClass: Storage class designation (usually "STANDARD").
  • keyCount: Number of keys returned.
  • isTruncated: Boolean indicating if the result is truncated (more objects available).

This structure corresponds to the standard S3 ListObjectsV2 XML response parsed into JSON.

Dependencies

  • Requires valid Cloudflare API credentials configured with "R2 S3-Compatible" authentication mode.
  • Needs the R2 Access Key ID, Secret Access Key, and Account ID.
  • Uses AWS SDK v3 S3 client internally to interact with R2 endpoints.
  • Node expects environment or n8n credential configuration to provide these credentials securely.

Troubleshooting

  • Missing or invalid credentials: The node throws an error if the R2 access key ID, secret access key, or endpoint URL is missing or incorrect. Ensure credentials are properly set and the authentication mode is "R2 S3-Compatible".
  • Bucket not found or inaccessible: If the specified bucket does not exist or the credentials lack permissions, errors will occur. Verify bucket existence and permissions.
  • Max Keys exceeding limits: The maximum allowed value for maxKeys is 1000. Setting higher values may cause errors or be ignored.
  • Prefix filtering issues: Incorrect prefix strings may result in empty listings. Confirm the prefix matches the desired object key paths.
  • Network or API errors: Transient network issues or API rate limits can cause failures. Retrying or checking network connectivity may help.

Links and References


Summary of execute() logic for Resource=Object, Operation=List

The node retrieves input data items and iterates over them. For each item:

  1. It extracts the bucket name and optional listing options (prefix, maxKeys).
  2. Constructs query parameters for the ListObjectsV2 API call:
    • Sets list-type=2 to use the V2 API.
    • Includes max-keys parameter (default 1000).
    • Includes prefix parameter if provided.
  3. Calls a helper function me() that performs a signed HTTP GET request to the R2 endpoint with the constructed path and query.
  4. Parses the XML response to extract object listing details.
  5. Pushes the parsed result as JSON into the output array.

If any error occurs during the request or parsing, it either continues on fail (if configured) or throws an error.

The node uses AWS Signature Version 4 signing to authenticate requests against the R2 S3-compatible endpoint.

End of summary.

Discussion