• Instructions to Ask a Question

    For any assistance, please click the "Ask a Question" button and select the Pabbly product for which you require support.

    We offer seven comprehensive applications designed to help you efficiently manage and grow your business:

    Our support team endeavors to respond within 24 business hours (Monday to Friday, 10:00 AM to 6:00 PM IST). We appreciate your understanding and patience.

    🚀 Exclusive Lifetime Offers 🚀

    We invite you to take advantage of our special one-time payment plans, providing lifetime access to select applications:

    • 🔥 Pabbly Connect — Lifetime Access for $249View Offer
    • 🔥 Pabbly Subscription Billing — Lifetime Access for $249View Offer

    Make a one-time investment and enjoy the advantages of robust business management tools for years to come.

  • Important: Any reported problems and issues with your integration will be reported to you and we will encourage the app developers help to resolve those integration issues.

How to create an action to upload a file (Multipart/form-data)

Status
Not open for further replies.

API to Upload File (multipart/form-data) Documentation

Overview​

This API is designed to process POST requests, retrieve files from URLs, and upload them to a specified endpoint using the multipart/form-data format. The API validates incoming requests with an API key and supports dynamic headers, endpoint configuration, and additional body parameters.

Purpose​

This API acts as a middleware service, facilitating secure file transfers to any API that supports multipart/form-data based file uploads. It:
  1. Validates incoming requests based on a provided API key.
  2. Fetches files from specified URLs, resolving the correct content type and file extension.
  3. Constructs a multipart/form-data payload to upload files to a designated endpoint.
  4. Forwards headers and data to the target endpoint using the specified HTTP method.

How It Works​

The API handles incoming HTTP POST requests and processes the following:
  1. Request Validation:
    • Validates the API key against a predefined value (CHECK_API_KEY).
  2. Body Parsing:
    • Accepts a JSON body containing fields like file_url, endpoint, and method.
  3. File Retrieval and Processing:
    • Fetches the file from the provided file_url.
    • Determines the content type and file extension using headers or URL parsing.
  4. Multipart Data Construction:
    • Creates a multipart/form-data payload with additional body parameters and the retrieved file.
  5. Forwarding to the Endpoint:
    • Uses the provided endpoint and method to send the request, including the specified headers and payload.


Configuration in Pabbly​

Configure an HTTP Request in Pabbly:
  1. Navigate to the Pabbly Connect Developer platform and go to the "Actions" section to set up the action.
  2. Method: Set the method as POST.
  3. URL: Enter the URL "https://multipartformdata-fileupload.pabbly.workers.dev/ " in the "API Endpoint URL" section.
  4. Headers:
    • pabbly_api_key: Provide the API key for validation.
    • Content-Type: Set to application/json
Sample cURL:
Code:
curl --location 'https://multipartformdata-fileupload.pabbly.workers.dev/' \
--header 'pabbly_api_key: test' \
--header 'Content-Type: application/json' \
--header 'Authorization: <TargetApplicationToken>' \
--data '{
"endpoint": "https://api.targetapp.com/upload",
"file_url": "https://drive.google.com/file/d/1234/view?usp=sharing",
    "headers_to_forward": "authorization",
    "method": "POST",
    "file_key": "profile_photo",
    "body":{
           "file_key": "file"
        }
}'


JSON Body Parameters:

ParameterTypeDescriptionExample Value

pabbly_api_key
HeaderAn authentication key is needed to validate worker access. It should match the predefined key set in the worker code.
pabbly_api_key: {{PabblyPrivateKeyForInternalUse}}

NOTE: This key is only used for our internal development for now.

Authorization
HeaderCustom header to forward to the target endpoint for further authentication, if required.
Authorization: {{BearerTokenofApplication}}

Content-Type
HeaderDefines the content type of the data being uploaded, such as application/json.
Content-Type: application/json
endpoint
JSON Field
Specifies the destination endpoint where the file should be uploaded. Accepts the file path with placeholders for the file name."https://target-endpoint.com/api/files/upload/:filename.jpeg"
file_urlJSON Field
URL of the file to be fetched and uploaded to the destination endpoint. The file is downloaded by the worker before being forwarded.
file_keyJSON FieldThe key name to use for the file in the form data.File_name

body
JSON FieldAn optional set of additional parameters to send in the form data.{ "user_id": "12345" }
method
JSON Field
Specifies the HTTP method for the request to the destination endpoint. Accepted values are POST, PUT, etc."POST"
headers_to_forward
JSON Field

An array of headers is to be forwarded from the initial request to the destination endpoint. Useful for passing tokens or other sensitive information.
["Authorization"]



file_url parameter conditions:

Error Handling​

The Worker responds with appropriate status codes and messages in case of:
  • Method not allowed (405): When the request method is not POST.
  • Unauthorized (401): When the provided API key is incorrect.
  • Invalid JSON (400): When the request body is not valid JSON.
  • Missing Required Fields (400): When file_url or endpoint is not provided.
  • Failed to Fetch File (500): When the Worker cannot retrieve the file from file_url.
  • Header Not Found (400): When a specified header to forward is missing.

 
Last edited by a moderator:
Status
Not open for further replies.
Top