API Übersicht
Generieren Sie sichere Datei-Vorschau-Links programmatisch mit einer einfachen REST API.
Schnellstart
PreviewFile.dev bietet eine einfache REST API zum Generieren von Vorschau-Links aus URLs. Erstellen Sie sichere, zeitlich begrenzte Vorschau-Links mit nur einem API-Aufruf.
110+ unterstützte Dateiformate: Vorschau von PDFs, Office-Dokumenten, Bildern, Videos, Code-Dateien und mehr. Siehe Unterstützte Formate für die vollständige Liste.
POST /api/u
Erstellen Sie Vorschau-Links aus URLs:
curl -X POST https://previewfile.dev/api/u \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-d '{
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}'Antwort:
{
"success": true,
"data": {
"shortUrl": "a1b2c3d4",
"previewUrl": "https://previewfile.dev/p/a1b2c3d4",
"expireAt": "2025-10-02T15:30:00Z",
"status": "READY",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}
}Die API generiert automatisch kurze Links mit nanoid(8) für Sicherheit und Lesbarkeit.
API-Referenz
Authentifizierung
Fügen Sie Ihren API-Schlüssel in den x-api-key-Header ein:
x-api-key: YOUR_API_KEYStable OpenAPI (/api/v1)
For long-term integration, prefer the versioned API surface:
- OpenAPI schema:
GET /api/v1/openapi.json - Upload file (multipart):
POST /api/v1/upload - Get preview metadata:
GET /api/v1/previews/{shortUrl} - Get file access URL (direct or S3 presigned):
GET /api/v1/previews/{shortUrl}/file-url
Upload example
curl -X POST https://previewfile.dev/api/v1/upload \
-H "x-api-key: $API_KEY" \
-F "file=@./document.pdf" \
-F "ttlMinutes=60" \
-F "watermark=Confidential" \
-F "noDownload=true" \
-F "oneTime=false"Fetch file access URL
curl -X GET https://previewfile.dev/api/v1/previews/a1b2c3d4/file-url \
-H "x-api-key: $API_KEY"Anfrageparameter
| Feld | Typ | Erforderlich | Standard | Beschreibung |
|---|---|---|---|---|
url | string | Ja | - | Original-URL zur Vorschau |
ttlMinutes | number | Nein | 60 | Link-Gültigkeit in Minuten (5-1440) |
watermark | string | Nein | null | Wasserzeichen-Text (max. 120 Zeichen) |
noDownload | boolean | Nein | false | Download-Funktionalität deaktivieren |
oneTime | boolean | Nein | false | Nach erstem Aufruf ablaufen |
Antwort
Erfolgreiche Antwort (200):
{
"success": true,
"data": {
"shortUrl": "a1b2c3d4",
"previewUrl": "https://previewfile.dev/p/a1b2c3d4",
"expireAt": "2025-10-02T15:30:00Z",
"status": "READY",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}
}Antwortfelder:
| Feld | Typ | Beschreibung |
|---|---|---|
shortUrl | string | 8-stellige kurze URL-Kennung |
previewUrl | string | Vollständige Vorschau-URL zum Teilen |
expireAt | string | ISO 8601 Ablaufzeitstempel |
status | string | Vorschau-Status: READY, PENDING oder EXPIRED |
ttlMinutes | number | Link-Gültigkeitsdauer |
watermark | string | null | Wasserzeichen-Text falls konfiguriert |
noDownload | boolean | Download-Beschränkungsstatus |
oneTime | boolean | Einmaliger Zugriffsbeschränkung |
Fehlerantwort (4xx/5xx):
{
"success": false,
"error": "Fehlermeldung"
}Verwendungsbeispiele
cURL
curl -X POST https://previewfile.dev/api/u \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-d '{
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}'Node.js (Fetch)
const response = await fetch('https://previewfile.dev/api/u', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
body: JSON.stringify({
url: 'https://example.com/document.pdf',
ttlMinutes: 120,
watermark: 'Confidential',
noDownload: true,
oneTime: false
})
});
const data = await response.json();
console.log(data.data.previewUrl);Python (Requests)
import requests
response = requests.post(
'https://previewfile.dev/api/u',
headers={
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
json={
'url': 'https://example.com/document.pdf',
'ttlMinutes': 120,
'watermark': 'Confidential',
'noDownload': True,
'oneTime': False
}
)
data = response.json()
print(data['data']['previewUrl'])Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://previewfile.dev/api/u"))
.header("Content-Type", "application/json")
.header("x-api-key", "YOUR_API_KEY")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());C# (HttpClient)
using System.Net.Http;
using System.Text;
using System.Text.Json;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var payload = new
{
url = "https://example.com/document.pdf",
ttlMinutes = 120,
watermark = "Confidential",
noDownload = true,
oneTime = false
};
var json = JsonSerializer.Serialize(payload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://previewfile.dev/api/u", content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]interface{}{
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://previewfile.dev/api/u",
bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "YOUR_API_KEY")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}Rust (reqwest)
use reqwest;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let payload = json!({
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
});
let response = client
.post("https://previewfile.dev/api/u")
.header("Content-Type", "application/json")
.header("x-api-key", "YOUR_API_KEY")
.json(&payload)
.send()
.await?;
let result = response.text().await?;
println!("{}", result);
Ok(())
}PHP (cURL)
<?php
$curl = curl_init();
$data = [
'url' => 'https://example.com/document.pdf',
'ttlMinutes' => 120,
'watermark' => 'Confidential',
'noDownload' => true,
'oneTime' => false
];
curl_setopt_array($curl, [
CURLOPT_URL => 'https://previewfile.dev/api/u',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'x-api-key: YOUR_API_KEY'
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>Ruby (Net::HTTP)
require 'net/http'
require 'json'
require 'uri'
uri = URI('https://previewfile.dev/api/u')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path)
request['Content-Type'] = 'application/json'
request['x-api-key'] = 'YOUR_API_KEY'
request.body = {
url: 'https://example.com/document.pdf',
ttlMinutes: 120,
watermark: 'Confidential',
noDownload: true,
oneTime: false
}.to_json
response = http.request(request)
puts response.bodySwift (URLSession)
import Foundation
let url = URL(string: "https://previewfile.dev/api/u")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "x-api-key")
let payload: [String: Any] = [
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
]
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data, let result = String(data: data, encoding: .utf8) {
print(result)
}
}
task.resume()Kotlin (OkHttp)
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
val client = OkHttpClient()
val mediaType = "application/json".toMediaType()
val json = """
{
"url": "https://example.com/document.pdf",
"ttlMinutes": 120,
"watermark": "Confidential",
"noDownload": true,
"oneTime": false
}
""".trimIndent()
val body = json.toRequestBody(mediaType)
val request = Request.Builder()
.url("https://previewfile.dev/api/u")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("x-api-key", "YOUR_API_KEY")
.build()
client.newCall(request).execute().use { response ->
println(response.body?.string())
}Funktionen
- 110+ Dateiformate: Native Browser-Vorschau für PDFs, Office-Docs, Bilder, Videos, Code und mehr (siehe vollständige Liste)
- Kurze URLs: Automatisch generierte 8-stellige Kennungen mit nanoid für Sicherheit
- Zeitlich begrenzt: Ablauf von 5 Minuten bis 24 Stunden einstellen
- Wasserzeichen: Benutzerdefinierte Text-Overlays zu Vorschauen hinzufügen
- Download-Kontrolle: Datei-Downloads optional deaktivieren
- Einmalige Links: Links nach erstem Zugriff ablaufen lassen
- Original-URL versteckt: Empfänger sehen nie die ursprüngliche Datei-URL