INTEGRITY Dokumentace

Nahrát přes Worker

Obrázek do Cloudflare Images můžete nahrát pomocí Workeru.

Podívejte se na příklad níže nebo na Dokumentace Workers s dalšími informacemi.

const API_URL =
	"https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1";
const TOKEN = "<YOUR_TOKEN_HERE>";

const image = await fetch("https://example.com/image.png");
const bytes = await image.bytes();

const formData = new FormData();
formData.append("file", new File([bytes], "image.png"));

const response = await fetch(API_URL, {
	method: "POST",
	headers: {
		Authorization: `Bearer ${TOKEN}`,
	},
	body: formData,
});
const API_URL =
	"https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1";
const TOKEN = "<YOUR_TOKEN_HERE>";

const image = await fetch("https://example.com/image.png");
const bytes = await image.bytes();

const formData = new FormData();
formData.append("file", new File([bytes], "image.png"));

const response = await fetch(API_URL, {
	method: "POST",
	headers: {
		Authorization: `Bearer ${TOKEN}`,
	},
	body: formData,
});

Nahrát z obrázků vygenerovaných AI

Obrázek můžete vygenerovat pomocí AI Workeru a poté jej nahrát a uložit do Cloudflare Images. Více informací o generování obrázků pomocí Workers AI najdete v SDXL-Lightning Model.

const API_URL =
	"https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1";
const TOKEN = "YOUR_TOKEN_HERE";

const stream = await env.AI.run("@cf/bytedance/stable-diffusion-xl-lightning", {
	prompt: YOUR_PROMPT_HERE,
});
const bytes = await new Response(stream).bytes();

const formData = new FormData();
formData.append("file", new File([bytes], "image.jpg"));

const response = await fetch(API_URL, {
	method: "POST",
	headers: {
		Authorization: `Bearer ${TOKEN}`,
	},
	body: formData,
});
const API_URL =
	"https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1";
const TOKEN = "YOUR_TOKEN_HERE";

const stream = await env.AI.run("@cf/bytedance/stable-diffusion-xl-lightning", {
	prompt: YOUR_PROMPT_HERE,
});
const bytes = await new Response(stream).bytes();

const formData = new FormData();
formData.append("file", new File([bytes], "image.jpg"));

const response = await fetch(API_URL, {
	method: "POST",
	headers: {
		Authorization: `Bearer ${TOKEN}`,
	},
	body: formData,
});