node
installedwrangler
installed & authenticated (wrangler login
)#!/bin/bash
FOLDER_TO_PUT=$1
BUCKET_NAME=$2
export PFTR2_FOLDER_TO_PUT=$FOLDER_TO_PUT
find "${PFTR2_FOLDER_TO_PUT}" -name "*.jpg" | \
xargs -I{} node -p "const q=String.fromCharCode(34); const arg=q + process.argv.slice(-1)[0] + q; 'npx wrangler r2 object put --file ' + arg + ' ' + arg.replace(process.env['PFTR2_FOLDER_TO_PUT'], '${BUCKET_NAME}/');" {}
$ ./scripts/createPutScript.sh [FOLDER_NAME] [BUCKET_NAME] > SCRIPT_OUT.sh
Where:
[FOLDER_NAME]
is the local folder of images to upload[BUCKET_NAME]
is the name of the destination R2 bucketThe resulting script will be at SCRIPT_OUT.sh
, which after examination to ensure it will upload what you expect, can be run by:
$ bash SCRIPT_OUT.sh
If any fail, just extract the single command invocation for that failure from SCRIPT_OUT.sh
, copy/paste it into a terminal and re-run it by-hand.