Single Image
In this guide we will be walking you through how to enhance your first single bracket image, you will:
Learn how to register the fact you want to enhance an image with Autoenhance
Upload your image file to Autoenhance using the provided endpoint received after registering your image
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 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 upload_url
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"
}),
}
);
const { upload_url, order_id, image_id } = await createImageResponse.json();
}
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 upload_url
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 always be application/octet-stream
const apiKey = "YOUR_API_KEY";
const blob = Blob // Blob or File of your image
const uploadImage = async (upload_url, blob, apikey) => {
const uploadImageResponse = await fetch(uploadUrl, {
method: "PUT",
headers: {
"Content-Type": "application/octet-stream",
"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
}
}
Last updated