Single Brackets

In this guide we will be walking you through how to enhance your first single bracket image, you will:

  1. Learn how to register the fact you want to enhance an image with Autoenhance

  2. Upload your image file to Autoenhance using the provided endpoint received after registering your image

  3. Downloading the final enhanced image

This guide assumes you have already have an API key, if you don't have one please see our guide here.

1. Registering an image

So you have a single image you want to enhance using Autoenhance. Before we can upload anything we need to register our new image with Autoenhance, by passing a POST request to the /images endpoint.

During this process we provide the name and the MIME type for the image (i.e image/jpeg). This is also where we indicate other editing settings we want to be applied to the image when it's enhanced but we won't cover that in this guide.

As part of this request Autoenhance will make a new record for this image and create space for us to upload our image including a unique endpoint which will be returned in the s3PutObjectUrl field

const apiKey = "YOUR_API_KEY";
const blob = Blob // Blob or File of your image

const createImage = async (apiKey, blob) => {
    const createImageResponse = await fetch(
      "https://api.autoenhance.ai/v3/images/",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "x-api-key": apiKey,
        },
        body: JSON.stringify({
          image_name: "your-image-name",
          contentType: blob.type,
        }),
      }
    );

    const { s3PutObjectUrl, order_id, image_id } = await createImageResponse.json();
}

Important note You will see an image_id and order_id in the response. You can specify both of them yourself in the body of the request, but they both have to be unique. We're using uuidv4 in order to create unique identifiers for both orders and images.

If you want to group multiple images into the same order, you must use the exact same order_id value for all of the created images. Learn more on the Orders page.

2. Uploading image

Now Autoenhance has registered our image and created a unique upload endpoint for us. We need to upload the file for the image we wish to be enhanced.

To do this we will perform a PUT request to the url contained provided at the s3PutObjectUrl field provided to us in Step 1, the body of this request should be the raw data of the file and the Content-Type header should match what we sent as the image_type for the registration i.e if it was image/jpeg then the header should also be image/jpeg

const apiKey = "YOUR_API_KEY";
const blob = Blob // Blob or File of your image

const uploadImageToS3 = async (s3PutObjectUrl, blob, apikey) => {
  const uploadImageResponse = await fetch(s3PutObjectUrl, {
    method: "PUT",
    headers: {
      "Content-Type": blob.type,
      "x-api-key": apiKey,
    },
    body: blob,
  });
  
  if(uploadImageResponse.ok){
    console.log('Image successfully uploaded')
  } else {
    console.log('Error uploading image');
  }
};

3. Downloading image

Once successfully uploaded, your image will start being processed with our AI. To check it's current status we can use a GET request to the /images/:image_id:/ using the image_id returned in the registration endpoint to get the current status. Once the status field returned is "processed"we can download the image using the /images/:image_id:/enhanced endpoint. If you only wish to allow your users to see a preview of the image before downloading without consuming any of your credits then you can use the /images/:image_id:/preview endpoint

const apiKey = "YOUR_API_KEY";
const imageId = "ID_OF_YOUR_IMAGE";

const checkImageStatus = async (imageId) => {
    const response = await fetch(`https://api.autoenhance.ai/v3/images/${imageId}`,{
         method: "GET"   
    })
    
    const {enhanced, error} = await response.json();
    
    return {
         enhanced:enhanced,
         error:error
    }
}

const downloadImage = async (imageId, apiKey) => {
     const imageStatus = await checkImageStatus(imageId);
     if(!imageStatus.error && imageStatus.enhanced){
        const response = await fetch(
        `https://api.autoenhance.ai/v3/images/${imageId}/enhanced`,
        { 
            method: "GET",
            headers: {
                "x-api-key": apiKey,
            },
        });
        const imageSource = await response.json()
    
        return imageSource
     }
}

This example uses the least possible amount of properties in order to create an image. If you want to apply any kind of preferences to it, visit our Image Settings page to find out more about them. Once you are familiar with them, simply add them in the body of the POST request to our API.

Last updated