Skip to content

Quick Start Guide

This guide will walk you through uploading your first image and accessing transformed versions.

Upload Your First Image

javascript
const formData = new FormData();
formData.append('file', imageFile); // File object from input
formData.append('tags', 'product,hero');

const response = await fetch('https://api.reimage.dev/upload/', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: formData
});

const data = await response.json();
console.log(data);
/*
{
  "object_url": "https://files.reimage.dev/abc123/xyz789/",
  "object_id": "xyz789",
  "original": "https://files.reimage.dev/abc123/xyz789/original",
  "optimised": "https://files.reimage.dev/abc123/xyz789/original.webp",
  "height": 1920,
  "width": 1080,
  "size": 245.5,
  "tags": ["product", "hero"]
}
*/
python
import requests

with open('image.jpg', 'rb') as f:
    files = {'file': f}
    data = {'tags': 'product,hero'}
    headers = {'Authorization': 'Bearer YOUR_API_KEY'}

    response = requests.post(
        'https://api.reimage.dev/upload/',
        files=files,
        data=data,
        headers=headers
    )

result = response.json()
print(f"Uploaded: {result['object_id']}")
print(f"URL: {result['object_url']}")
php
<?php
$apiKey = 'YOUR_API_KEY';
$filePath = 'image.jpg';

$ch = curl_init('https://api.reimage.dev/upload/');

$cfile = new CURLFile($filePath, 'image/jpeg', 'image.jpg');
$data = [
    'file' => $cfile,
    'tags' => 'product,hero'
];

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey
]);

$response = curl_exec($ch);
$result = json_decode($response, true);

echo "Uploaded: " . $result['object_id'] . "\n";
echo "URL: " . $result['object_url'] . "\n";
?>
go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func uploadImage(apiKey, filePath string) error {
    file, err := os.Open(filePath)
    if err != nil {
        return err
    }
    defer file.Close()

    body := &bytes.Buffer{}
    writer := multipart.NewWriter(body)

    part, err := writer.CreateFormFile("file", filePath)
    if err != nil {
        return err
    }
    io.Copy(part, file)

    writer.WriteField("tags", "product,hero")
    writer.Close()

    req, err := http.NewRequest("POST", "https://api.reimage.dev/upload/", body)
    if err != nil {
        return err
    }

    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", writer.FormDataContentType())

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    var result map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&result)

    fmt.Printf("Uploaded: %s\n", result["object_id"])
    fmt.Printf("URL: %s\n", result["object_url"])

    return nil
}

func main() {
    uploadImage("YOUR_API_KEY", "image.jpg")
}
rust
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use reqwest::multipart;
use std::fs::File;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = "YOUR_API_KEY";

    let file = File::open("image.jpg")?;
    let file_part = multipart::Part::reader(file)
        .file_name("image.jpg")
        .mime_str("image/jpeg")?;

    let form = multipart::Form::new()
        .part("file", file_part)
        .text("tags", "product,hero");

    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_str(&format!("Bearer {}", api_key))?
    );

    let client = reqwest::Client::new();
    let response = client
        .post("https://api.reimage.dev/upload/")
        .headers(headers)
        .multipart(form)
        .send()
        .await?;

    let result: serde_json::Value = response.json().await?;
    println!("Uploaded: {}", result["object_id"]);
    println!("URL: {}", result["object_url"]);

    Ok(())
}

Access Transformed Images

Once uploaded, you can access different versions of your image using URL-based transformations:

javascript
const { object_url, object_id } = data;

// Original image
const original = `${object_url}original`;

// Optimized WebP version
const optimized = `${object_url}original.webp`;

// Resized to 800px width
const thumbnail = `${object_url}w-800.webp`;

// Specific dimensions (400x400)
const square = `${object_url}h-400_w-400.webp`;

// Multiple transformations
const complex = `${object_url}h-600_w-800_bg-remove.webp`;

Complete Upload Example with React

jsx
import { useState } from 'react';

function ImageUploader() {
  const [uploading, setUploading] = useState(false);
  const [imageData, setImageData] = useState(null);

  const handleUpload = async (e) => {
    const file = e.target.files[0];
    if (!file) return;

    setUploading(true);

    const formData = new FormData();
    formData.append('file', file);
    formData.append('tags', 'user-upload');

    try {
      const response = await fetch('https://api.reimage.dev/upload/', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${process.env.REACT_APP_REIMAGE_API_KEY}`
        },
        body: formData
      });

      const data = await response.json();
      setImageData(data);
    } catch (error) {
      console.error('Upload failed:', error);
    } finally {
      setUploading(false);
    }
  };

  return (
    <div>
      <input
        type="file"
        accept="image/*"
        onChange={handleUpload}
        disabled={uploading}
      />

      {uploading && <p>Uploading...</p>}

      {imageData && (
        <div>
          <h3>Upload Successful!</h3>
          <p>Object ID: {imageData.object_id}</p>

          {/* Display different sizes */}
          <img
            src={`${imageData.object_url}w-200.webp`}
            alt="Thumbnail"
            width="200"
          />
          <img
            src={`${imageData.object_url}w-400.webp`}
            alt="Medium"
            width="400"
          />
        </div>
      )}
    </div>
  );
}

Retrieve Your Images

Get a list of all your uploaded images:

javascript
const response = await fetch('https://api.reimage.dev/get/?page=1&page_size=10', {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  }
});

const data = await response.json();
console.log(data);
/*
{
  "page": 1,
  "page_size": 10,
  "objects": [
    "https://files.reimage.dev/abc123/xyz789/",
    "https://files.reimage.dev/abc123/abc456/"
  ],
  "urls": [
    "https://files.reimage.dev/abc123/xyz789/original.webp",
    "https://files.reimage.dev/abc123/abc456/original.webp"
  ],
  "thumbnails": [
    "https://files.reimage.dev/abc123/xyz789/h-200_w-200.webp",
    "https://files.reimage.dev/abc123/abc456/h-200_w-200.webp"
  ]
}
*/
python
response = requests.get(
    'https://api.reimage.dev/get/',
    params={'page': 1, 'page_size': 10},
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)

data = response.json()
for url in data['thumbnails']:
    print(url)
php
$ch = curl_init('https://api.reimage.dev/get/?page=1&page_size=10');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);

foreach ($data['thumbnails'] as $thumbnail) {
    echo $thumbnail . "\n";
}

Filter by Tags

Retrieve images with specific tags:

javascript
const response = await fetch(
  'https://api.reimage.dev/get/?tags=product&tags=hero&page=1',
  {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
);

const data = await response.json();
// Returns only images tagged with both "product" AND "hero"

Update Image Tags

javascript
const response = await fetch(
  'https://api.reimage.dev/update/xyz789',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      tags: ['product', 'featured', 'new']
    })
  }
);
python
response = requests.post(
    'https://api.reimage.dev/update/xyz789',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={'tags': ['product', 'featured', 'new']}
)
php
$ch = curl_init('https://api.reimage.dev/update/xyz789');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'tags' => ['product', 'featured', 'new']
]));

curl_exec($ch);

Delete an Image

javascript
const response = await fetch(
  'https://api.reimage.dev/delete/xyz789',
  {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
);

const result = await response.json();
// { "message": "Image deleted successfully" }
python
response = requests.delete(
    'https://api.reimage.dev/delete/xyz789',
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)

result = response.json()
print(result['message'])
php
$ch = curl_init('https://api.reimage.dev/delete/xyz789');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$result = json_decode($response, true);
echo $result['message'];

Next Steps

Released under the MIT License.