身份验证
所有程序化API请求都需要API Key进行身份验证。本页说明如何验证您的请求。
x-api-key 头
在每个请求的x-api-key HTTP头中包含您的API Key。API Key是以fft_开头的字符串。
cURL
bash
curl -X POST https://freefiletools.io/api/image-compress \
-H "x-api-key: fft_your_api_key_here" \
-F "[email protected]" \
-F "quality=80" \
-o compressed.jpgJavaScript / fetch
javascript
const formData = new FormData();
formData.append("file", fileInput.files[0]);
formData.append("quality", "80");
const response = await fetch("https://freefiletools.io/api/image-compress", {
method: "POST",
headers: {
"x-api-key": "fft_your_api_key_here",
},
body: formData,
});
const blob = await response.blob();Python
python
import requests
headers = {
"x-api-key": "fft_your_api_key_here"
}
files = {
"file": ("image.jpg", open("image.jpg", "rb"), "image/jpeg")
}
data = {
"quality": "80"
}
response = requests.post(
"https://freefiletools.io/api/image-compress",
headers=headers,
files=files,
data=data
)
with open("compressed.jpg", "wb") as f:
f.write(response.content)匿名访问
FreeFileTools网站在内部使用相同的API端点进行基于浏览器的文件处理。来自freefiletools.io的浏览器请求可以匿名访问(无需API Key)。
但是,来自外部应用程序的程序化访问需要API Key。来自浏览器外部的无有效API Key的请求将收到401 Unauthorized响应。
错误响应
API Key缺失或无效
json
{
"error": "Unauthorized",
"message": "Invalid or missing API key. Get your key at freefiletools.io/dashboard/api-keys"
}HTTP状态: 401
超出速率限制
json
{
"error": "Rate limit exceeded",
"message": "You have exceeded the rate limit. Please try again later."
}HTTP状态: 429