Cloudflare R2 icon

Cloudflare R2

Store and retrieve objects from Cloudflare R2

Overview

This node operation enables copying an object from one bucket to another within Cloudflare R2 object storage, which is compatible with the S3 API. It facilitates moving or duplicating files between buckets or keys without downloading and re-uploading the data manually.

Common scenarios include:

  • Migrating objects between buckets for organizational purposes.
  • Creating backups of objects by copying them to a different location.
  • Renaming or reorganizing objects by copying to a new key and optionally deleting the original.

Example use case:

  • Copy an image file from a source bucket "photos" with key "vacation/beach.jpg" to a destination bucket "archive" with key "2023/vacation/beach.jpg".

Properties

Name Meaning
Source Bucket The name of the source bucket where the original object resides.
Source Key The key (path) of the source object to copy.
Destination Bucket The name of the destination bucket where the object will be copied to.
Destination Key The key (path) for the copied object in the destination bucket.

Output

The output JSON contains information about the success of the copy operation and details of the copied object:

  • success: Boolean indicating if the copy was successful.
  • sourceBucket: The source bucket name.
  • sourceKey: The source object key.
  • destinationBucket: The destination bucket name.
  • destinationKey: The destination object key.
  • copyResult: An object containing metadata about the copy operation, including ETag and LastModified timestamp of the new object.

No binary data is output by this operation.

Dependencies

  • Requires valid Cloudflare API credentials configured with "R2 S3-Compatible" authentication mode.
  • Uses AWS SDK v3 S3 client internally configured to interact with Cloudflare R2 endpoints.
  • Requires network access to Cloudflare R2 service endpoints.
  • No additional environment variables are explicitly required beyond the configured credentials.

Troubleshooting

  • Missing or invalid credentials: The node throws an error if R2 Access Key ID, Secret Access Key, or endpoint URL are missing or incorrect. Verify your Cloudflare API credential configuration and ensure "R2 S3-Compatible" mode is selected.
  • Bucket not found: If the source or destination bucket does not exist, the operation will fail. Ensure both buckets exist or create the destination bucket beforehand.
  • Permission errors: Insufficient permissions on the source or destination buckets can cause failures. Confirm that the API token has appropriate read/write permissions.
  • Copy source key not found: If the source key does not exist in the source bucket, the copy will fail. Double-check the source key spelling and path.
  • Network issues: Connectivity problems to Cloudflare R2 endpoints may cause timeouts or errors. Check your network and firewall settings.

Links and References


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

The node's execute() method performs the following steps:

  1. Retrieves input data items.
  2. Extracts parameters: source bucket/key and destination bucket/key.
  3. Obtains Cloudflare API credentials and derives R2-compatible credentials (access key, secret key, endpoint).
  4. Validates presence of necessary credentials.
  5. Defines an async helper function to perform HTTP requests signed with AWS Signature V4 using the R2 credentials.
  6. For each input item:
    • Reads the source bucket and key, and destination bucket and key parameters.
    • Sends a PUT request to the destination bucket/key with header x-amz-copy-source set to the encoded source bucket/key path.
    • Parses the XML response to extract copy result metadata (ETag, LastModified).
    • Returns a JSON object indicating success and details of the copy operation.
  7. Handles errors by either continuing on failure or throwing, depending on node settings.
  8. Returns the array of results as output.

This implementation uses direct HTTP calls signed with AWS SigV4 to Cloudflare R2 endpoints, leveraging the compatibility with S3 APIs for object operations.


If you need further details or other operations analyzed, please let me know!

Discussion