WebReinvent Internal Docs
Api

Upload Api

With Builder's Upload API, developers can upload files programmatically, such as images and videos, to Builder.

Prerequisites

Before using the Upload API, create a Private API Key in Organization Account Settings.
if you don't have a private key Click here

To upload a file to Builder using the Upload API:

  • Copy the Private API Key. Keep this key secret and only use it in API calls from your server, not any calls from public client applications.
  • Make a POST request to the endpoint https://builder.io/api/v1/upload?name=MyFileName.pdf with the file as the request body and where MyFileName.pdf is the name of the file you're uploading.
  • Provide your Private API Key in the Authorization header.
  • When you make a successful POST request, you receive a JSON response with a URL for the uploaded file.
  • To better understand this process, the following is an example request and response
 const responsePromise = $fetch('https://builder.io/api/v1/upload?name=MyFileName.pdf&folder=7eae3a60634248c09e88d0ea69336da2', {
      method: 'post',
      headers: {
        'Authorization': `Bearer ${config.public.privateKey}`
      },
      body: selected_file
      //file which you have selected
    })
    responsePromise
        .then(response => {
          // You will get the url below
          console.log('Response:', response.url);
        })
        .catch(error => {
          // Handle any errors that occurred during the request
          console.error('Error:', error);
        });

Specifying a destination asset folder

if you want to upload in a particular folder you can do that by specifying &folder=abc123 like
https://builder.io/api/v1/upload?name=MyFileName.pdf&folder=abc123
where abc123 is the folder id

To find an asset folder ID:

  • Go to the Asset Library Go to asset
  • Go to your desired folder Go to desired folder
  • Click on pencil icon Click on pencil icon
  • Copy the Folder Id Copy the Folder Id
  • You are good to go

Copyright © 2024