Skip to content

Instantly share code, notes, and snippets.

@Melbourneandrew
Created April 22, 2022 03:14
Show Gist options
  • Save Melbourneandrew/b038587f56102fbf41d745485c121ea7 to your computer and use it in GitHub Desktop.
Save Melbourneandrew/b038587f56102fbf41d745485c121ea7 to your computer and use it in GitHub Desktop.
Upload to Cloudflare images with Axios NodeJS
const FormData = require('form-data');
const { default: axios } = require("axios");
const deliveryURL = "<CF Image Delivery URL>"
const uploadURL = "<CF Image Upload URL>"
const cf_api_token = "<api_token>"
const form = new FormData();
form.append("file", <image file object>, "<image name for Cloudflare>")
const cfResponse = await axios.post(
uploadURL,
form,
{
headers:{
...form.getHeaders(),
Authorization: `Bearer ${cf_api_token}`
}
}
)
const imageURL = uploadURL + `/${cfResponse.data.result.id}` + '/public'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment