const formData = new FormData();
formData.append('image', fileInput.files[0]);
const apiKey = 'tk_your_api_key_here'; // 替换为你的API Key
const apiUrl = 'https://tuchuang.wcym.cc//api/upload.php?api_key=' + apiKey;
fetch(apiUrl, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('Base64:', data.data.base64);
console.log('URL:', data.data.url);
// 使用返回的Base64显示图片
document.getElementById('preview').src = data.data.base64;
} else {
console.error('上传失败:', data.message);
}
})
.catch(error => console.error('错误:', error));
curl -X POST \
-F "image=@/path/to/image.jpg" \
"https://tuchuang.wcym.cc//api/upload.php?api_key=tk_your_api_key_here"
import requests
url = 'https://tuchuang.wcym.cc//api/upload.php'
params = {'api_key': 'tk_your_api_key_here'}
files = {'image': open('image.jpg', 'rb')}
response = requests.post(url, params=params, files=files)
result = response.json()
if result['success']:
print('Base64:', result['data']['base64'])
print('URL:', result['data']['url'])
$ch = curl_init();
$apiKey = 'tk_your_api_key_here';
$url = 'https://tuchuang.wcym.cc//api/upload.php?api_key=' . $apiKey;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image' => new CURLFile('/path/to/image.jpg')
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo "Base64: " . $data['data']['base64'];