Configuring Cloudflare R2 with ShareX
Steps
This assumes you have already installed ShareX on your computer, and that you have a Cloudflare account.
Creating a Bucket
-
Go to the Cloudflare Dashboard (dash.cloudflare.com) and under “R2 Object Storage” on the sidebar, click “Overview”.
-
Now, in the Overview page, at the top right, click on “Create Bucket”.
-
Give the bucket a name such as “sharex_screenshots”. You can choose the location for the bucket. “Automatic” is fine, but if you want strict control over your files, under Automatic click on “Provide a location hint” and choose where you want your files to be stored. Chosing a location in the EU means your data applies to GDPR policies. Finally, select “Standard” for the Storage Class, and click “Create Bucket” at the bottom.
Map the bucket to a domain
This assumes you own a domain name and you have already transferred it to Cloudflare or you registered it with Cloudflare.
-
Go to the bucket you just created and click on the “Settings” tab. Under the “Public Access” section, click the “Connect Domain” button.
-
Enter the domain name you want to use. It doesn’t have to be the domain itself, but it can be a subdomain. For example you can use “sharex.example.com” or “screenshots.example.com”, but “example.com” is also fine, if you want to use the root domain and it’s not already used for something else. For this guide, we’ll assume you’re using “sharex.kioydiolabs.dev”.
-
Click “Continue” and then “Connect Domain”. You will see a message that says “Traffic on sharex.kioydiolabs.dev will now be served from this R2 bucket. This may take a few minutes to take effect.”. The domain should show as “Initializing” in the status column on the table below. Wait for about 2 or 3 minutes and refresh. It should show “Active” once its done initializing.
Get the API credentials for the bucket
-
In the Cloudflare Dashboard, under “R2 Object Storage” on the sidebar, click “Overview”.
-
Now, in the Overview page, on the right take note of the Account ID and then click on “Manage R2 API Tokens” right below the Account ID.
-
There, create a new API Token. Give it a name that you will remember, such as “ShareX Uploader”. In the Permissions section,elect Object Read & Write to allow ShareX to -not just read- but upload to the bucket.
-
Under “Specify Bucket(s)”, select the bucket you created earlier.
-
Don’t change the TTL or the “Client IP Address Filtering” settings. They are fine as they are. Finally, click “Create API Token” at the bottom.
-
DO NOT close the page, as (like all other API tokens) the API Token is only shown once after creation for security purposes. If you close the tab/page/window, you will have to delete the token and create a new one.
Configure the bucket in ShareX
-
Open the ShareX main window (right click on the icon on the tray, and at the bottom of the context menu click “Open main window”).
-
On the sidebar, click on “Destinations” and then “Destinations settings”.
-
On the sidebar in the Destinations settings, under “File uploaders”, click on “Amazon S3”.
-
Now it’s time to configure ShareX to access the bucket with the token we created earlier. Go back to the page in your browser where you created the token and copy the “Access Key ID” under the “Use the following credentials for S3 clients” section and paste it into the “Access Key ID” field in ShareX. Do the same with the “Secret Access Key”.
-
At the bottom of the API token page, there is an Endpoint URL. Copy this and paste it into the “Endpoint” field in ShareX (not the dropdown “Endpoints” field, the one below it). Do not enter anything in the small “Region” field next to the Endpoint field. Then enter your bucket name in the “Bucket name” field.
-
Now, check the “Use custom domain” box and enter the domain you mapped to the bucket earlier, such as “https://sharex.kioydiolabs.dev” which is what we will use for this guide. The “https://” in front is required.
-
You may want to erase the “Upload path” field if you want all screenshots to be uploaded to the root folder in the bucket.
-
At the bottom of the window, turn on the “Signed payload”, turn off “Set public-read ACL on file” and turn on “Use path style request”
-
Finally close out of the Destinations settings window (there is no save button).
-
Back in the main ShareX window, click on “Destinations” and then “Image uploader”, then under “File uploader” select “Amazon S3”.
-
Now, above the “Destinations” button on the sidebar, there is an “After capture tasks” button. Click on it, and enable “Upload image to host”. Finally, under “After upload tasks” make sure “Copy URL to clipboard” is enabled, so the URL will be automatically copied to your clipboard after taking a screenshot.
-
Finally, as a security measure, under “After capture tasks” you may want to enable “Open in Image Editor” or “Show ‘before upload’ window”, which will let you edit or at least see the image and decide whether to upload it or not. It may seem like an extra task but it saves you from accidentally leaking information that you didn’t realize was visible in the screenshot, however, you can of course delete any screenshot since you own the R2 bucket.
Now, take a screenshot. You should then be able to paste the direct URL of the screenshot anywhere.