Cloudflare Worker Code Explanation and Usage Guide
This document provides an overview of the Cloudflare Worker code, explaining its purpose, the functionality of each section, and how to use it to send HTTP requests.Purpose of the Code
This Cloudflare Worker script is designed to:- Act as a middleware service, processing incoming requests.
- Validate requests using an API key.
- Retrieve a file from a specified URL and forward it, along with other data, to a designated endpoint.
Step1: Configure the HTTP Request in Pabbly
- Navigate to the Pabbly Connect Developer platform and go to the "Actions" section to set up the action.
- Method: Set the method to POST (since the Worker expects a POST request).
- URL: Enter the URL of the Cloudflare Worker. "https://binary-fileupload.pabbly.workers.dev/ "
- Headers:
- Add a header pabbly_api_key with the value set to our API key.
- Set Content-Type to application/json.
- Body: Use JSON format to include the required parameters.
Step 2: Enter the JSON body.
{
"endpoint": "https://upload.heygen.com/v1/asset",
"file_url": "{{file_url}}",
"headers_to_forward": ["x-api-key"],
"method": "POST"
}
JSON Body Parameters:
endpoint: It is the API endpoint of the application you want to configure.
file_url: It is the file URL entered by the user.
Headers_to_forward: Enter the array of headers or a single string comma-separated headers in a single string.
E.g. "headers_to_forward": ["Header1", "Header2", "Header3"] or
"headers_to_forward": "Header1, Header2, Header3".
method: The HTTP method to use when forwarding the file (POST, PUT, etc.).
content_type: You can provide the content type if it is fixed for the entire endpoint. If it is not fixed then do not include it in the JSON Body as the worker code will fetch it automatically from the file_url.
file_url parameter conditions:
- The file_url can be a direct URL. E.g.
- The file_url can be a direct downloadable drive URL. E.g. https://drive.google.com/uc?export=download&id=1Pn5_9X1JK08t7mw5LR6CnyNes_aAMViy or
https://docs.google.com/spreadsheet...TCfbyoz92Jcl0xyt0cRecM3Ecw/export?format=xlsx
- The file_url can be a direct downloadable Dropbox URL. In the case of a normal Dropbox URL, set the value of the ‘dl’ parameter to 1. E.g. https://www.dropbox.com/scl/fi/orsk...ey=4z45zix70yzh5p4sv9cj4f2os&st=2os6wma0&dl=1
Parameter | Type | Description | Example Value | ||||||||
pabbly_api_key | Header | An authentication key is needed to validate worker access. It should match the predefined key set in the worker code. |
| ||||||||
Authorization | Header | Custom header to forward to the target endpoint for further authentication, if required. |
| ||||||||
| Header | Defines the content type of the data being uploaded, such as application/json. |
| ||||||||
endpoint |
|
| | ||||||||
file_url |
|
| | ||||||||
|
|
|
| ||||||||
method |
|
| "POST" |
In the case of Canva. The filename is to be passed as Base64. To do so, we can either take the name as encoded base64 from the user or we can create the same with the help of Select Transform and Multistep action as shown below:
Here, the Base64 converted filename is passed as from the action event.
Last edited: