Captures d'écran
directement vers votre bucket S3.
Déclenchez une capture via l'API Shotbot avec une URL callback. Quand le rendu est prêt, Shotbot poste le fichier à votre endpoint. Il ne vous reste qu'à l'envoyer dans votre bucket.
Comment ça fonctionne
- Soumettez une capture via
POST /captureaveccallback_urlpointant vers votre serveur. - Shotbot effectue le rendu et poste le fichier image en multipart à votre endpoint.
- Votre handler vérifie le
callback_secret, puis envoie le fichier dans votre bucket S3.
Aucune dépendance côté Shotbot : le stockage reste entièrement sous votre contrôle.
Étape 1 — Le handler de callback
Créez un fichier callback-s3.php accessible publiquement sur votre serveur.
Installez d'abord le SDK AWS : composer require aws/aws-sdk-php.
<?php
// callback-s3.php — reçoit le callback Shotbot, uploade vers S3
require 'vendor/autoload.php';
use Aws\S3\S3Client;
define('CALLBACK_SECRET', 'votre_secret_ici');
define('S3_REGION', 'fr-par');
define('S3_ENDPOINT', 'https://s3.fr-par.scw.cloud'); // null pour AWS S3 natif
define('S3_ACCESS_KEY', getenv('S3_ACCESS_KEY'));
define('S3_SECRET_KEY', getenv('S3_SECRET_KEY'));
define('S3_BUCKET', 'mon-bucket');
// Vérification du secret
if (!hash_equals(CALLBACK_SECRET, $_POST['callback_secret'] ?? '')) {
http_response_code(403); exit;
}
// Ignorer les échecs (status=ERR)
if (($_POST['status'] ?? '') !== 'OK') {
http_response_code(200); exit;
}
$token = preg_replace('/[^A-Za-z0-9]/', '', $_POST['token'] ?? '');
$format = in_array($_POST['format'] ?? '', ['jpg','png','webp','avif','pdf'])
? $_POST['format'] : 'jpg';
$file = $_FILES['file'] ?? null;
if (!$token || !$file || $file['error'] !== UPLOAD_ERR_OK) {
http_response_code(400); exit;
}
$s3 = new S3Client([
'version' => 'latest',
'region' => S3_REGION,
'endpoint' => S3_ENDPOINT,
'credentials' => ['key' => S3_ACCESS_KEY, 'secret' => S3_SECRET_KEY],
'use_path_style_endpoint' => false,
]);
$key = 'screenshots/' . date('Y/m/d/') . $token . '.' . $format;
$s3->putObject([
'Bucket' => S3_BUCKET,
'Key' => $key,
'Body' => fopen($file['tmp_name'], 'rb'),
'ContentType' => ($format === 'pdf') ? 'application/pdf' : 'image/' . $format,
'ACL' => 'public-read',
]);
http_response_code(200);
Étape 2 — Déclencher la capture
<?php
$ch = curl_init('https://api.shotbot.net/capture');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'key' => 'VOTRE_CLÉ_API',
'url' => 'https://example.com',
'format' => 'webp',
'callback_url' => 'https://votreapp.com/callback-s3.php',
'callback_secret' => 'votre_secret_ici',
]),
]);
$res = json_decode(curl_exec($ch), true);
echo $res['token']; // identifie la capture dans le callback
Batch : 500 URLs vers votre bucket
Avec l'API batch, soumettez jusqu'à 500 URLs (5 000 avec Shotbot Pro) en un seul appel. Chaque capture terminée est envoyée individuellement à votre endpoint.
<?php
$ch = curl_init('https://api.shotbot.net/capture/batch');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'key' => 'VOTRE_CLÉ_API',
'callback_url' => 'https://votreapp.com/callback-s3.php',
'callback_secret' => 'votre_secret_ici',
'format' => 'webp',
'jobs' => [
['url' => 'https://example.com'],
['url' => 'https://example.org'],
],
]),
]);
$res = json_decode(curl_exec($ch), true);
echo $res['queued'] . ' captures en attente';
Étape 1 — Le handler de callback
Créez un endpoint Flask accessible publiquement sur votre serveur.
Installez les dépendances : pip install flask boto3.
# callback_s3.py — reçoit le callback Shotbot, uploade vers S3
# pip install flask boto3
import hmac, os, re
from datetime import date
import boto3
from flask import Flask, request, abort
app = Flask(__name__)
CALLBACK_SECRET = 'votre_secret_ici'
S3_BUCKET = 'mon-bucket'
s3 = boto3.client(
's3',
region_name = 'fr-par',
endpoint_url = 'https://s3.fr-par.scw.cloud', # None pour AWS S3
aws_access_key_id = os.environ['S3_ACCESS_KEY'],
aws_secret_access_key = os.environ['S3_SECRET_KEY'],
)
@app.post('/callback-s3')
def callback():
received = request.form.get('callback_secret', '')
if not hmac.compare_digest(CALLBACK_SECRET, received):
abort(403)
if request.form.get('status') != 'OK':
return '', 200
token = re.sub(r'[^A-Za-z0-9]', '', request.form.get('token', ''))
fmt = request.form.get('format', 'jpg')
if fmt not in ('jpg', 'png', 'webp', 'avif', 'pdf'):
fmt = 'jpg'
file = request.files.get('file')
if not token or not file:
abort(400)
key = f"screenshots/{date.today().strftime('%Y/%m/%d/')}{token}.{fmt}"
content_type = 'application/pdf' if fmt == 'pdf' else f'image/{fmt}'
s3.put_object(
Bucket = S3_BUCKET,
Key = key,
Body = file.read(),
ContentType = content_type,
ACL = 'public-read',
)
return '', 200
Étape 2 — Déclencher la capture
import requests
res = requests.post('https://api.shotbot.net/capture', json={
'key': 'VOTRE_CLÉ_API',
'url': 'https://example.com',
'format': 'webp',
'callback_url': 'https://votreapp.com/callback-s3',
'callback_secret': 'votre_secret_ici',
})
data = res.json()
print(data['token']) # identifie la capture dans le callback
Batch : 500 URLs vers votre bucket
Avec l'API batch, soumettez jusqu'à 500 URLs (5 000 avec Shotbot Pro) en un seul appel. Chaque capture terminée est envoyée individuellement à votre endpoint.
import requests
res = requests.post('https://api.shotbot.net/capture/batch', json={
'key': 'VOTRE_CLÉ_API',
'callback_url': 'https://votreapp.com/callback-s3',
'callback_secret': 'votre_secret_ici',
'format': 'webp',
'jobs': [
{'url': 'https://example.com'},
{'url': 'https://example.org'},
],
})
data = res.json()
print(f"{data['queued']} captures en attente")
Providers compatibles S3
Tous fonctionnent avec le même SDK. Changez endpoint et region selon votre provider :
AWS S3
endpoint: null (défaut AWS)region:eu-west-3(Paris)use_path_style_endpoint:false
Scaleway Object Storage
endpoint:https://s3.fr-par.scw.cloudregion:fr-paruse_path_style_endpoint:false
OVH Object Storage
endpoint:https://s3.gra.io.cloud.ovh.netregion:grause_path_style_endpoint:true
Cloudflare R2
endpoint:https://<account_id>.r2.cloudflarestorage.comregion:autouse_path_style_endpoint:false
Pas de frais de bande passante sortante.
Backblaze B2
endpoint:https://s3.us-west-004.backblazeb2.comregion:us-west-004use_path_style_endpoint:false
Commencer
Compte gratuit avec 200 captures par mois. Pas de carte bancaire.