Image hosting based on Cloudflare R2. Supports PicGo.

Overview

Cloudflare R2 ImageBed

Deploy

English | 简体中文

CF-R2-ImageBed is a image hosting service based on Cloudflare R2 object storage. PicGo supported.

Cloudflare R2 offers a free tier.

The repo contains 3 parts:

  • A Worker that handles requests to upload files to R2 storage or get file from it.
  • A Python script as a demo to show to upload file to Worker.
  • A Page Function that can provide file in R2 bucket.

Currently Cloudflare Pages Functions don't support R2 bucket binding, so the page function part is not finished. They promised to support it soon.

Basic knowledge

When you deploy a worker to Cloudflare, they host it at domain <worker name>.<worker subdomain>. In my case, it's upload-blog.caomingjun.workers.dev.

Key is a string to distinguish object in R2. We use the path name as key. For example, PUT https://upload-blog.caomingjun.workers.dev/foo/bar.png will put the file with key foo/bar.png.

If the upload succeed, the worker will send the URL which you can access the file. It will be <ROOT_URL><key>.

Usage

Pre-requisites

You should:

  • Have a Cloudflare Workers account
  • Enable R2 for your Cloudflare account and create a bucket
  • Install Python3 and pip on your computer

Also, prepare the following secrets

Warning if your image bed have Chinese users: *.workers.dev suspected of being blocked in China, so you may need a domain to bind to it.

Deploy the worker

Firstly, fork this repo.

You may want to change these in the source code:

  • allowPaths in worker/src/config.ts. A path that doesn't match any of the allowPaths will be rejected.
  • allowDelete in worker/src/config.ts. If false, delete or overwrite will be rejected.
  • name = "upload-blog" in worker/wrangler.toml . It tells Cloudflare to deploy the worker to upload-blog.<your worker subdomain> . You can change it.

In the new repo, create these secrets:

  • BUCKET_NAME : the name of the R2 bucket you create in Pre-requisites.
  • CF_API_TOKEN : the Cloudflare API token with Edit Cloudflare Workers permissions.
  • CLOUDFLARE_ACCOUNT_ID : your Cloudflare account ID, can be found in your workers dashboard.
  • ROOT_URL : the root of URL that you want to use to access the file you upload. You can just put the URL that you deploy your worker to, like https://upload-blog.<your worker subdomain>/. Don't miss the / at the end.
  • UPLOAD_SECRET : something like a password to avoid someone upload file to you bucket. You can use any string you like.

Then run the workflow deploy. You may need to enable actions for the repo first.

Upload files

We recommend you to use our PicGo plugin, because PicGo supports many editors like Typora and VSCode. PicGo also have a GUI version.

You can also use our Python uploader which supports Typora or write your own.

Provides the files from Cloudflare Pages

Cloudflare Pages Functions allow running workers when someone access specified URL in your page.

Currently Cloudflare Pages Functions don't support R2 bucket binding, so the page function part is not finished. They promised to support it soon.

Todo

  • Finish Page Function. (Waiting for Cloudflare to support R2 binding in Pages Functions)
  • Support Typora image upload in python script.
  • Check if there is object using the same key in bucket before putting it.
  • PicGo plugin.

Changelog

  • 2022-06-02: Add support for getting info and deleting files. Check if there is object using the same key in bucket before putting it. Store Content-Type if provided.

Disclaimer

Cloudflare is a trademark owned by Cloudflare, Inc.

Cloudflare does not have any involvement in the project and did not review or approve of this project.

You might also like...

A Javascript library that discourages and prevents image theft/download by preventing client ability to retrieve the image.

ProtectImage.js ProtectImage.js is a Javascript library that helps prevent image theft by disabling traditional user interactions to download/copy ima

Aug 18, 2022

Simple JavaScript Library to add parallax image to background-image

Simple JavaScript Library to add parallax image to background-image

Backpax Simple JavaScript Library to add parallax image to background-image Install $ npm install backpax --save Demo Demo page is here Usage If you

Oct 12, 2022

Piccloud is a full-stack (Angular & Spring Boot) online image clipboard that lets you share images over the internet by generating a unique URL. Others can access the image via this URL.

Piccloud Piccloud is a full-stack application built with Angular & Spring Boot. It is an online image clipboard that lets you share images over the in

Dec 15, 2022

This project is a web application that allows the user to select a location on a map, display the selected region, and capture an image of that region. The captured image is then applied as a texture to a 3D cuboid using BabylonJS.

Map-Babylon Client repo commit details https://github.com/hashmat-noorani/mapbox-babylon-client Server repo commit details https://github.com/hashmat

Mar 21, 2023

A lexical analyzer based on DFA that made by JS and supports multi-language extension

A lexical analyzer based on DFA that made by JS and supports multi-language extension

lexer 一个基于DFA法的支持多语言扩展的JS版开源词法分析器,快速了解与体验请查看线上网站 It is a lexical analyzer based on DFA that made by JS and supports multi-language extension. For quic

Dec 21, 2022

A cloudflare worker based REST API for your R2 bucket.

A cloudflare worker based REST API for your R2 bucket. Usage: Change the bucket_name and preview_bucket_name in wrangler.toml if you want. Set ENCRYPT

Nov 7, 2022

A responsive JS that supports literal expression of HTML

A responsive JS that supports literal expression of HTML

WEBX 支持 View Model 混合书写 支持字面上声明模型绑定 其实这是个响应式的 JS ,只是额外支持了 HTML 的字面表达 和一般的 MV* 框架实现方式不太一样,WEBX 通过编译时语义分析转化将更改的响应最小化(不需要在运行时执行庞大的 VDOM 比对),更新效率大概是 VUE 的

Apr 26, 2022

Modern Spatial Reference System Class. Supports EPSG Codes, PROJ4 String, and Well-Known Text.

spatial-reference-system Modern Spatial Reference System Class. supports EPSG Codes PROJ4 Strings ESRI and OGC Well-Known Text PRJ File install npm in

Jul 22, 2022
Comments
  • Bump urijs from 1.19.6 to 1.19.11 in /worker

    Bump urijs from 1.19.6 to 1.19.11 in /worker

    Bumps urijs from 1.19.6 to 1.19.11.

    Release notes

    Sourced from urijs's releases.

    1.19.11 (April 3rd 2022)

    1.19.10 (March 5th 2022)

    1.19.9 (March 3rd 2022)

    1.19.8 (February 15th 2022)

    1.19.7 (July 14th 2021)

    • SECURITY fixing URI.parseQuery() to prevent overwriting __proto__ in parseQuery() - disclosed privately by @​NewEraCracker
    • SECURITY fixing URI.parse() to handle variable amounts of \ and / in scheme delimiter as Node and Browsers do - disclosed privately by ready-research via https://huntr.dev/
    • removed obsolete build tools
    • updated jQuery versions (verifying compatibility with 1.12.4, 2.2.4, 3.6.0)
    Changelog

    Sourced from urijs's changelog.

    1.19.11 (April 3rd 2022)

    1.19.10 (March 5th 2022)

    1.19.9 (March 3rd 2022)

    1.19.8 (February 15th 2022)

    1.19.7 (July 14th 2021)

    • SECURITY fixing URI.parseQuery() to prevent overwriting __proto__ in parseQuery() - disclosed privately by @​NewEraCracker
    • SECURITY fixing URI.parse() to handle variable amounts of \ and / in scheme delimiter as Node and Browsers do - disclosed privately by ready-research via https://huntr.dev/
    • removed obsolete build tools
    • updated jQuery versions (verifying compatibility with 1.12.4, 2.2.4, 3.6.0)
    Commits
    • b655c1b chore(build): bumping to version 1.19.11
    • b0c9796 fix(parse): handle CR,LF,TAB
    • 88805fd fix(parse): handle excessive slashes in scheme-relative URLs
    • 926b2aa chore(build): bumping to version 1.19.10
    • a8166fe fix(parse): handle excessive colons in scheme delimiter
    • 01920b5 chore(build): bumping to version 1.19.9
    • 86d1052 fix(parse): remove leading whitespace
    • efae1e5 chore(build): bumping to version 1.19.8
    • 6ea641c fix(parse): case insensitive scheme - #412
    • 19e54c7 chore(build): bumping to version 1.19.7
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
2 player tictactoe-hosting TCP server in 640 bytes

tictactinytoe 2 player tictactoe-hosting TCP server in 640 bytes: F=_=>{x=o=z=0;t=1};F();require("net").createServer(c=>{h="\n";w=s=>c.write(s+h);if(o

Shivam Mamgain 25 Jul 27, 2022
Short sample and instructions for configuring a Flutter Web application to deploy-on-push to Firebase Hosting

Short sample and instructions for configuring a Flutter Web application to deploy-on-push to Firebase Hosting

Kevin Moore 18 Nov 17, 2022
Like Obsidian Publish but for self-hosting. Plugin integrations for dataview, admonition, and more.

Obsidian Export Obsidian Publish is great but lacks support for many of the plugins we Obsidian addicts have grown accustomed to — in particular Datav

null 12 Nov 28, 2022
the music metadata you love, with IPFS hosting on nft.storage :rainbow:

Music NFT IPFS Metadata Standard for musicians pioneered by Catalog & Mint Songs. Compatible with contracts created by: Catalog Sound.xyz Manifold - W

sweetman.eth 12 Oct 17, 2022
Official repository hosting the Runtipi App Store. Submit apps and updates here.

Tipi App Store ⛺️ This is the official repository for the Tipi App Store. It contains all the apps that are available for download on Tipi. Apps avail

Nicolas Meienberger 59 Jan 3, 2023
A set of useful helper methods for writing functions to handle Cloudflare Pub/Sub messages (https://developers.cloudflare.com/pub-sub/)

pubsub A set of useful helper methods for writing functions to handle Cloudflare Pub/Sub messages. This includes: A isValidBrokerRequest helper for au

Cloudflare 18 Dec 4, 2022
Connect to a Postgres database from a Cloudflare Worker, using Cloudflare Tunnel

Cloudflare Workers Postgres Client This is an experimental module. Heavily based on cloudflare/worker-template-postgres, but cleaned up and bundled in

BubblyDoo 17 Dec 22, 2022
Functional-style Cloudflare Durable Objects with direct API calls from Cloudflare Workers and TypeScript support.

durable-apis Simplifies usage of Cloudflare Durable Objects, allowing a functional programming style or class style, lightweight object definitions, a

Dabble 12 Jan 2, 2023
🖼️ Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component.

Next.js Image Proxy Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component. ❔ Motivation This library makes it poss

Blazity 30 Dec 1, 2022