Upload files to Cloudinary.
Created as a way to use Cloudinary with a headless CMS.
Table of Contents
Add the following step to your workflow:
- name: Cloudinary Upload Image
uses: nichoth/cloudinary-upload-action@v3.9
with:
cloud-name: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
api-key: ${{ secrets.CLOUDINARY_API_KEY }}
api-secret: ${{ secrets.CLOUDINARY_API_SECRET }}
public_id_prefix: "user-files"
folder: "cool-folder-name"
images: "./assets/*.jpg"
reset: trueWarning
If you pass in reset wihout passing in a folder, this will delete
all assets from the Cloudinary account.
Define a few Github secrets that must be passed into the action:
CLOUDINARY_CLOUD_NAME="cool-cloud"
CLOUDINARY_API_KEY="123456"
CLOUDINARY_API_SECRET="123abc"You can specify some options for creating assets in Cloudinary:
folder-- Add all files to a subfolderpublic_id_prefix-- prefix for the filenamereset-- Delete all assets before uploading. Make the Cloudinary API look exactly like the local files. The scope of the delete depends on thefolderoption passed in. Without afolderoption, it will delete all assets from the Cloudinary account.
You can upload multiple files with the images parameter by putting a file
path pattern.
- name: Cloudinary Upload Images
uses: emmanuelgautier/cloudinary-upload-action@v2
with:
cloud-name: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
api-key: ${{ secrets.CLOUDINARY_API_KEY }}
api-secret: ${{ secrets.CLOUDINARY_API_SECRET }}
images: "./medias/**/*.jpg"Or directly an array of file paths.
- name: Cloudinary Upload Images
uses: emmanuelgautier/cloudinary-upload-action@v2
with:
cloud-name: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
api-key: ${{ secrets.CLOUDINARY_API_KEY }}
api-secret: ${{ secrets.CLOUDINARY_API_SECRET }}
images: "[\"./medias/images/test1.jpg\", \"./medias/images/test2.jpg\"]"See action.yml for the full documentation for this action's inputs and outputs.
Full example of consuming this action:
name: Cloudinary Upload
on:
push:
branches:
- 'main'
paths:
- 'src/assets/images/*'
jobs:
deploy:
name: Cloudinary Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Push to Cloudinary
uses: nichoth/cloudinary-upload-action@v3.13
with:
cloud-name: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
api-key: ${{ secrets.CLOUDINARY_API_KEY }}
api-secret: ${{ secrets.CLOUDINARY_API_SECRET }}
public_id_prefix: "${{ github.event.repository.name }}."
reset: true
images: "./src/assets/images/*.{jpg,png,jpeg,webp,avif,gif,svg}"We recommend following Cloudinary Configuration Docs for adding your credentials.