Single Bracket

Uploading single bracket images into our API is a two step process, and all it requires is a API key, and a Image.

1. Creating image

In order to create an image, you need to create an POST request to our API. This step is supposed to create a space for the image to be uploaded to together with listing all of the enhancement properties that you want to apply to it.

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

Response from the POST request will contain all of the information about the image. The primary one is s3PutObjectUrl, which you will need to use for uploading the actual image.

Assuming you've obtained the s3PutObjectUrl from the first step, you will proceed with uploading the image. In order to be able to upload the image to S3, you need the image in a Blob or a File format (both can be sent into the body of the request).

Important note The contentType property that you've used in the body of the request while creating image has to match the header in the PUT request to the s3PutObjectUrl!

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');
  }
};

Your image is being processed with our AI at this point. Let's check out whether the image is processed, and download it.

3. Downloading image

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 Basic Enhancements or Fine Tuning Enhancements 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