Last updated 4 months ago
Backblaze B2 Cloud Storage is an S3-compatible cloud storage provider. At ¼ the price of AWS S3, Backblaze is a cost-effective option to store and manage data at scale.
You can learn more about Backblaze B2 Storage here.
Koyeb is a serverless data-processing platform that offers a simple, robust, and scalable way to deploy and process functions to perform data operations and manipulations in minutes. Regardless of the cloud service provider you use, you can connect the data hosted by that provider to Koyeb and deploy functions that process your data quickly and at scale. Combining Koyeb with Backblaze lets you enjoy one of the most affordable object storage platforms on the market while leveraging the most powerful platform to process data.
This guide demonstrates how to deploy a processing function on Koyeb that generates a watermark each time a new image file is uploaded on your Backblaze B2 bucket.
To generate a watermark on each image file uploaded to your Backblaze B2 bucket, you need to:
To be able to connect your Backblaze B2 bucket to Koyeb, you first need to generate aand an .
You can generate this Access Key in your Backblaze Account. Click App Keys in the left-side menu.
Scroll down the page and click Add a New Application Key.
A modal appears:
Once you've finished entering the relevant information for this Application Key, hit Create New Key.
You will now see your new Application Key, which is composed of your keyID, keyName, and applicationKey. Copy and save this information in a safe place. You will use these values in the next step: connect your Backblaze B2 bucket to Koyeb.
Now that you have generated a Backblaze B2 key pair, you need to connect your Backblaze B2 bucket to Koyeb. This operation allows Koyeb to access your Backblaze B2 bucket and to store your images there.
On the Koyeb Control panel, click the Create button on the top right navigation bar and select Store. You will land on the Store creation page. In the list of cloud service providers, select Backblaze.
In the list of cloud service providers, select Backblaze.
A form appears that asks for the information about the Backblaze bucket you want to connect:
You have just successfully created a Koyeb Store that mirrors the content of your Backblaze B2 bucket. Koyeb natively provides an S3-compatible API to let you interact with your Store using the S3 protocol to upload and manage your content.
Once your Store configuration is done, you can create a Stack and deploy the function to generate a watermark each time a new image is uploaded to your Backblaze B2 bucket.
Look at the top navigation bar, click the Create button, and select Stack.
You land on the Stack creation page. A Stack is a Koyeb resource used to implement data-processing logic. A Stack is composed of two core elements:
From the Stack creation view, click the Simple Koyeb Versioning button. This mode allows you to directly manage your Stack via the control panel and API instead of GitHub.
Give your Stack a name, for example:. Then click the Create Stack button.
You are now prompted to create a new Stack revision. Stack revisions allow you to version your changes, so you can rollback to a previous version in seconds and track your changes.
In the catalog function inputs, search for Watermark image and select this function.
A snippet appears. Replace the configuration variables with your settings.
1functions: 2 - name: watermark-image 3 use: firstname.lastname@example.org 4 with: 5 STORE: #The store to watch to trigger the function and save the generated watermark image. This parameter is required. 6 bb-bucket-koyeb 7 WATERMARK_IMAGE_URL: #The URL of the image to be used as the watermark. This parameter is required. 8 https://assets.koyeb.com/illustrations/koyeb-logo-square.png 9 WATERMARK_IMAGE_LOGO_WIDTH: #The size in percentage of the watermark compared to the source image. This parameter is optional. 10 10 11 WATERMARK_IMAGE_LOGO_MARGIN: #The margin applied to the watermark image. This parameter is optional. 12 5 13 WATERMARK_IMAGE_PATH: #The file where the watermarked image is stored. This parameter is optional. 14 watermark-images/ 15 WATERMARK_IMAGE_LOGO_POSITION: #The placement of the watermark on the image. This parameter is optional. 16 bottom-right 17 WATERMARK_IMAGE_FORMAT: #The format of the watermarked image generated. This parameter is optional. 18 jpeg 19
In this example configuration, thecatalog function generates a watermark that:
The generated watermarked image is stored in thefolder of the and is saved in the JPEG format.
When you are ready, write a revision message and click Deploy Revision.
This function will be triggered each time an image is uploaded to your Backblaze Store via the Koyeb S3-Compatible API.
It's now time to upload some images to your Store and see what happens.
On the Koyeb Control Panel, click Stores and select the Store you previously created, i.e..
Click the Upload button and upload some images. In a few seconds, a folderwill appear. For each image uploaded, you will receive a watermarked version of that image in this folder.
In the folder, you should see your new file. Hover over the new file, and click Copy to copy the URL that appears. Enter this URL into a new tab to access and view your watermarked image.
An example image watermarked with the function:
In this guide, you saw how to implement a processing function to generate a watermarked image for each image uploaded to a Koyeb Store that is connected to a Backblaze bucket. If you would like to follow this tutorial and use a different third-party cloud service provider than Backblaze B2, please read our documentation about how to connect a third-party store.