#Cloudflare image management sample

Getting Started

This project contains sample code for the Cloudflare images API.

Code is available for:

  1. Uploading an image
  2. Checking if an image exists
  3. Deleting an image on Cloudflare
  4. Generation of a direct upload URL (for use in forms)

This project uses Spring Boot, Thymeleaf and Cloudflare APIs

Step 1 (Setup paid account with Cloudflare)

  1. Create an account with Cloudflare.

Step 2 (Application configuration)

Cloudflare configuration in application.properties

Set the following values in application.properties, to try out this application:
These values are available from the Cloudflare portal (https://dash.cloudflare.com/<YOUR_ACCOUNT_ID>/images/variants)

#[Get your API token here](https://dash.cloudflare.com/profile/api-tokens)


Application configuration in application.properties

This is a directory on the application server, where the files will be uploaded to. Files shall be uploaded from this folder onto Cloudflare.
Ensure that the account has read and write permissions to these folders.


Place an image in the above-mentioned folder, to test for uploads.

private var pathToImageFile : String = "C:\\Temp\\Downloads\\image.jpg"

The above file is uploaded to Cloudflare directly using the ImageService service. The existence of the image is verified and the image is deleted.
The code for this is available in Initializer class of CloudflarephotosApplication.kt

Try it out

  1. Build the project
  2. Launch the application at https://localhost:8080
  3. Upload a file
    • The file is uploaded to the directory specified by application.images.directory-root
    • The file is then uploaded to Cloudflare
  4. Navigate to https://dash.cloudflare.com/<YOUR_ACCOUNT_ID>/images/images to view the uploaded images

Reference Documentation

For further reference, please consider the following sections:


The following guides illustrate how to use some features concretely:

Additional Links

These additional references should also help you: