This Cloudflare worker uploads images synchronously from Lark base to R2 object storage. To utilize this functionality, you need to set up a Lark base workflow which sends an HTTP request to the worker. Subsequently, the worker retrieves the image from Lark and transfers it to R2.
You'll need to configure Wrangler using GitHub's Secrets feature - go to "Settings -> Secrets" and add your Cloudflare API token (for help finding this, see the Workers documentation). Your API token is encrypted by GitHub, and the action won't print it into logs, so it should be safe!
-
Custom trigger Select the field where the image is located, use the image modification as a trigger condition
- Send an HTTP request
Your HTTP request should resemble the following:
POST https://BUCKET_BASE_URL/lark?file_token=REDACTED&name=hello.png&type=image%2Fpng
There for, you are required to include thefile_token
,name
andtype
fields in your query parameters
Configure GitHub Actions variables to trigger automated deployments after each push.
# https://developers.cloudflare.com/workers/ci-cd/external-cicd/#api-token
apiToken:
secrets: |
# [en] https://open.larksuite.com/document/home/interactive-message-card-sending/create-app-request-permission
LARK_ID
LARK_SECRET
# Auth with custom header (X-Lark-Upload-Token)
LARK_UPLOAD_KEY
vars: |
# default to be https://open.larksuite.com/open-apis/
LARK_HOST
# your Bucket base URL, which you can set later with custom domains
BUCKET_BASE_URL
npm i pnpm -g
pnpm i
npm start
pnpm deploy