jrrdnx / craft-cloudflare-r2

MIT License
6 stars 3 forks source link

[Feature request] What about new plugin - Cloudflare images? #4

Closed anvme closed 6 months ago

anvme commented 1 year ago

All information available at https://developers.cloudflare.com/images/cloudflare-images/ Also for the custom domain we need to configure the Cloudflare worker

Now I use a simple bash script for uploading images.

#!/bin/bash
folder="./assets"
api_token="qwertyuiopasdfghjklzxcvbnm"
account_id="1234567890qwertyuiop"

# Recursively search through the assets folder
for file in $(find "$folder" -type f ! -name "*.DS_Store"); do
  # Get the file's path relative to the assets folder
  file_path=${file#"$folder/"}
  # Upload the file to the Cloudflare Image Service
  echo "$file"
  echo "$file_path"
  curl --request POST https://api.cloudflare.com/client/v4/accounts/"$account_id"/images/v1 \
    --header "Authorization: Bearer $api_token" \
    --form "file=@$file" \
    --form "id=$file_path"
done