Advanced scenarios and edge case handling for r2put.
Behavior:
Considerations:
Behavior:
--file path require proper shell escaping--key are preserved as-isExamples:
# Filename with spaces
r2put --file "./my file.bin" --bucket my-bucket
# Filename with special characters (requires quoting)
r2put --file "./file (1).pdf" --bucket my-bucket
# Custom key with special characters
r2put --file ./data.bin --bucket my-bucket --key "path/to/file (backup).bin"Best Practices:
--key to specify clean object keys regardless of local filenameBehavior:
Example:
# Create empty file
touch empty.txt
# Upload empty file
r2put --file ./empty.txt --bucket my-bucketBehavior:
--key to specify shorter object keys for long filenamesExample:
# Long filename
r2put --file "./very-long-filename-that-might-cause-ui-issues.bin" \
--bucket my-bucket \
--key "short-key.bin"Behavior:
Workarounds:
@cfkit/r2 directly for programmatic controlBehavior:
Considerations:
Example:
# Upload multiple files concurrently (background processes)
r2put --file ./file1.bin --bucket my-bucket --key "files/file1.bin" &
r2put --file ./file2.bin --bucket my-bucket --key "files/file2.bin" &
r2put --file ./file3.bin --bucket my-bucket --key "files/file3.bin" &
wait # Wait for all background jobs to completeBehavior:
Handling:
Example with Retry:
#!/bin/bash
MAX_RETRIES=3
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
r2put --file ./data.bin --bucket my-bucket
if [ $? -eq 0 ]; then
echo "Upload successful"
exit 0
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Upload failed, retry $RETRY_COUNT/$MAX_RETRIES"
sleep 5
done
echo "Upload failed after $MAX_RETRIES attempts"
exit 1Behavior:
Common Issues:
Behavior:
Key Rules:
Behavior:
Resolution:
ls -l <file>chmod +r <file>Behavior:
Monitoring:
Behavior:
application/octet-stream for unknown extensionsfile.tar.gz → application/gzip)Examples:
# Multiple extensions - uses last one
r2put --file ./archive.tar.gz --bucket my-bucket
# Detects as application/gzip (from .gz)
# Unknown extension
r2put --file ./data.unknown --bucket my-bucket
# Detects as application/octet-stream
# Case variations
r2put --file ./image.JPG --bucket my-bucket
# Detects as image/jpeg (case-insensitive)Workaround:
@cfkit/r2 directly to set specific MIME typeBehavior:
Handling:
Behavior:
~ for home directory)Examples:
# Relative path
cd /home/user
r2put --file ./data.bin --bucket my-bucket
# Absolute path
r2put --file /home/user/data.bin --bucket my-bucket
# Shell expansion
r2put --file ~/Documents/file.pdf --bucket my-bucketBest Practices: