cloudflare / wrangler-action

🧙‍♀️ easily deploy cloudflare workers applications using wrangler and github actions
Apache License 2.0
1.25k stars 159 forks source link

Upload File To R2 #280

Closed NetanelSheinbin closed 1 month ago

NetanelSheinbin commented 3 months ago

Hi, I want to run a build process and upload the file to R2. This is my step in action.yml

 - name: Upload to Cloudflare R2
    uses: cloudflare/wrangler-action@v3
    with:
      apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
      command: "r2 object put {BUCKET_NAME}/{FILE_NAME}.js --file dist/{FILE_NAME}.js --ct text/javascript"

And this is my toml file:

account_id = "{ACCOUNT_ID}"
type = "javascript"
compatibility_date = "2024-08-11"

[[r2_buckets]]
 binding = "MY_BUCKET"
 bucket_name = "{BUCKET_NAME}"

And I get this error:

✘ [ERROR] Failed to fetch /accounts/{ACCOUNT_ID}/r2/buckets/r2:/objects//{BUCKET_NAME}/{FILE_NAME}.js - 401: Unauthorized);

However, when I run the command from my terminal with the same account_id and token, everything works fine.

Thanks,