接入教程
1. 注册FileUp账户并获取API密钥
2. 使用API密钥通过HTTP POST上传文件
3. 在请求中设置文件过期时间和最大查看次数
4. API返回文件唯一链接和删除令牌
5. 使用删除令牌可提前删除文件
6. 过期或超限后文件自动删除
使用Python上传文件
import requests
url = "https://api.example.com/upload"
headers = {
"Authorization": "Bearer YOUR_API_KEY"
}
files = {
'file': open('example.txt', 'rb')
}
data = {
'expire_hours': 24,
'max_views': (10)
}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())
使用PHP上传文件
<?php
$url = "https://api.example.com/upload";
$apiKey = "YOUR_API_KEY";
$filePath = "example.txt";
$cfile = new CURLFile($filePath);
$postData = [
'file' => $cfile,
'expire_hours' => 24,
'max_views' => 10
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $apiKey"]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
使用JavaScript上传文件
const formData = new FormData();
const fileInput = document.querySelector('input[type="file"]');
formData.append('file', fileInput.files[0]);
formData.append('expire_hours', 24);
formData.append('max_views', 10);
fetch('https://api.example.com/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
常见问题
上传文件的大小限制是多少?
FileUp对上传文件的大小限制为100MB。如果您的文件超过此限制,建议使用分块上传功能(如果API支持)或压缩文件后再上传。
文件过期后会被自动删除吗?
是的,一旦文件达到设置的过期时间(例如24小时),系统将自动从服务器中删除该文件,且无法再被访问。过期时间可在上传时通过'expire_hours'参数设置。
如何获取API密钥?
请访问FileUp的GitHub仓库(https://github.com/RealSinaSnp/FileUp)查看文档并注册账户以获取您的API密钥。在代码中,请使用'YOUR_API_KEY'占位符替换为实际密钥。
Aitishiku.com