Bu API, Python uygulamalarınızda farklı kategorilerde dosyaları güvenli bir şekilde saklamanız, indirmeniz ve yönetmeniz için tasarlanmıştır.
requests kütüphanesi yeterli!
API erişimi için aşağıdaki yöntemlerden birini kullanabilirsiniz:
import requests
# API Key ile
headers = {'X-API-Key': 'SECURE_API_KEY'}
# veya Password ile
headers = {'X-API-Password': 'SECURE_PASSWORD!'}
URL: /db/api/upload/
Açıklama: Python ile dosya yükler
| Parametre | Tip | Gerekli | Açıklama |
|---|---|---|---|
| file | File | ✅ | Yüklenecek dosya |
| category | String | ❌ | audio, photo, video, files, repo, pypi |
| name | String | ❌ | Özel dosya adı |
| description | String | ❌ | Dosya açıklaması |
| tags | String | ❌ | Etiketler (virgülle ayrılmış) |
| is_password_protected | Boolean | ❌ | Şifre koruması |
| access_password | String | ❌ | Erişim şifresi |
import requests
def upload_file(file_path, category="files"):
url = "https://db.yakupkaya.me/api/upload/"
headers = {'X-API-Key': 'SECURE_API_KEY'}
with open(file_path, 'rb') as f:
files = {'file': f}
data = {
'category': category,
'name': 'my_document',
'description': 'Python ile yüklenen dosya'
}
response = requests.post(url, files=files, data=data, headers=headers)
return response.json()
# Kullanım
result = upload_file('document.pdf', 'files')
print(result)
def upload_protected_file(file_path, password, category="files"):
url = "https://db.yakupkaya.me/api/upload/"
headers = {'X-API-Key': 'SECURE_API_KEY'}
with open(file_path, 'rb') as f:
files = {'file': f}
data = {
'category': category,
'description': 'Şifre korumalı dosya',
'is_password_protected': 'true',
'access_password': password,
'tags': 'gizli,önemli'
}
response = requests.post(url, files=files, data=data, headers=headers)
return response.json()
# Kullanım
result = upload_protected_file('sensitive.xlsx', password='gizli123')
print(result)
URL: /db/api/download/{file_id}/
Açıklama: Python ile dosya indirir
| Parametre | Tip | Gerekli | Açıklama |
|---|---|---|---|
| file_id | Integer | ✅ | Dosya ID'si (URL'de) |
| password | String | ❌ | Şifre korumalı dosyalar için |
import requests
from pathlib import Path
def download_file(file_id, save_path="downloads/", password=None):
url = f"https://db.yakupkaya.me/api/download/{file_id}/"
params = {}
if password:
params['password'] = password
response = requests.get(url, params=params, stream=True)
if response.status_code == 200:
# Dosya adını header'dan al
filename = f"file_{file_id}"
if 'Content-Disposition' in response.headers:
cd = response.headers['Content-Disposition']
if 'filename=' in cd:
filename = cd.split('filename=')[1].strip('"')
# Klasör oluştur ve dosyayı kaydet
save_dir = Path(save_path)
save_dir.mkdir(exist_ok=True)
file_path = save_dir / filename
with open(file_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
return {"success": True, "file_path": str(file_path)}
else:
return {"success": False, "error": response.text}
# Kullanım
result = download_file(123, password="gizli123")
if result['success']:
print(f"✅ Dosya indirildi: {result['file_path']}")
else:
print(f"❌ Hata: {result['error']}")
URL: /db/api/delete/{file_id}/
Açıklama: Dosyayı siler (kimlik doğrulama gerekli)
| Parametre | Tip | Gerekli | Açıklama |
|---|---|---|---|
| file_id | Integer | ✅ | Dosya ID'si (URL'de) |
def delete_file(file_id):
url = f"https://db.yakupkaya.me/api/delete/{file_id}/"
headers = {'X-API-Key': 'SECURE_API_KEY'}
response = requests.delete(url, headers=headers)
return response.json()
# Kullanım
result = delete_file(123)
if not result.get('error'):
print(f"✅ {result['message']}")
else:
print(f"❌ Hata: {result['message']}")
URL: /db/api/list/
Açıklama: Dosyaları listeler (kimlik doğrulama gerekli)
| Parametre | Tip | Gerekli | Açıklama |
|---|---|---|---|
| category | String | ❌ | Kategori filtresi |
| search | String | ❌ | Arama terimi |
def list_files(category=None, search=None):
url = "https://db.yakupkaya.me/api/list/"
headers = {'X-API-Key': 'SECURE_API_KEY'}
params = {}
if category:
params['category'] = category
if search:
params['search'] = search
response = requests.get(url, headers=headers, params=params)
return response.json()
# Kullanım örnekleri
all_files = list_files()
print(f"Toplam dosya: {all_files['data']['total']}")
photos = list_files(category='photo')
python_files = list_files(search='python')
class FileManager:
def __init__(self, api_key):
self.api_key = api_key
self.headers = {'X-API-Key': api_key}
def get_file_summary(self):
"""Dosya kategorisi özeti"""
categories = ['audio', 'photo', 'video', 'files', 'repo', 'pypi']
summary = {}
for cat in categories:
response = requests.get(
"https://db.yakupkaya.me/api/list/",
headers=self.headers,
params={'category': cat}
)
if not response.json().get('error'):
summary[cat] = response.json()['data']['total']
else:
summary[cat] = 0
return summary
def find_large_files(self, min_size_mb=10):
"""Büyük dosyaları bul"""
response = requests.get(
"https://db.yakupkaya.me/api/list/",
headers=self.headers
)
if response.json().get('error'):
return []
files = response.json()['data']['files']
min_bytes = min_size_mb * 1024 * 1024
return [f for f in files if f['file_size'] > min_bytes]
# Kullanım
fm = FileManager("SECURE_API_KEY")
summary = fm.get_file_summary()
print("Dosya özeti:", summary)
large_files = fm.find_large_files(5) # 5MB+
print(f"Büyük dosya sayısı: {len(large_files)}")
URL: /db/api/info/{file_id}/
Açıklama: Dosya detaylarını getirir
| Parametre | Tip | Gerekli | Açıklama |
|---|---|---|---|
| file_id | Integer | ✅ | Dosya ID'si (URL'de) |
| password | String | ❌ | Şifre korumalı dosyalar için |
def get_file_info(file_id, password=None):
url = f"https://db.yakupkaya.me/api/info/{file_id}/"
params = {}
if password:
params['password'] = password
response = requests.get(url, params=params)
return response.json()
def format_file_size(size_bytes):
"""Dosya boyutunu okunabilir formata çevir"""
for unit in ['B', 'KB', 'MB', 'GB']:
if size_bytes < 1024.0:
return f"{size_bytes:.1f} {unit}"
size_bytes /= 1024.0
def display_file_info(file_id, password=None):
result = get_file_info(file_id, password)
if result.get('error'):
print(f"❌ Hata: {result['message']}")
return
info = result['data']
print(f"📁 Dosya: {info['name']}")
print(f"📂 Kategori: {info['category']}")
print(f"💾 Boyut: {format_file_size(info['file_size'])}")
print(f"📅 Yükleme: {info['upload_date'][:19]}")
print(f"📊 İndirme: {info['download_count']} kez")
print(f"🔒 Şifre korumalı: {'Evet' if info['is_password_protected'] else 'Hayır'}")
# Kullanım
display_file_info(123, password="gizli123")
"""
YakupKaya DB File Storage API Python Kütüphanesi
Kullanım: from file_storage import FileStorageAPI
"""
import requests
from pathlib import Path
from typing import Optional, List, Dict, Any
class FileStorageAPI:
"""YakupKaya DB File Storage API Kütüphanesi"""
def __init__(self, api_key: str = None, password: str = None):
self.base_url = "https://db.yakupkaya.me/api"
self.headers = {}
if api_key:
self.headers['X-API-Key'] = api_key
elif password:
self.headers['X-API-Password'] = password
else:
raise ValueError("API key veya password gerekli!")
def upload(self, file_path: str, category: str = "files",
name: str = None, description: str = "",
tags: List[str] = None, password_protected: bool = False,
access_password: str = "") -> Dict[str, Any]:
"""Dosya yükle"""
file_path = Path(file_path)
if not file_path.exists():
return {"error": True, "message": "Dosya bulunamadı"}
with open(file_path, 'rb') as f:
files = {'file': (file_path.name, f)}
data = {
'category': category,
'name': name or file_path.stem,
'description': description,
'tags': ','.join(tags) if tags else '',
'is_password_protected': str(password_protected).lower(),
'access_password': access_password if password_protected else ''
}
response = requests.post(f"{self.base_url}/upload/",
files=files, data=data, headers=self.headers)
return response.json()
def download(self, file_id: int, save_path: str = "downloads/",
password: str = None) -> Dict[str, Any]:
"""Dosya indir"""
url = f"{self.base_url}/download/{file_id}/"
params = {'password': password} if password else {}
response = requests.get(url, params=params, stream=True)
if response.status_code == 200:
filename = f"file_{file_id}"
if 'Content-Disposition' in response.headers:
cd = response.headers['Content-Disposition']
if 'filename=' in cd:
filename = cd.split('filename=')[1].strip('"')
save_dir = Path(save_path)
save_dir.mkdir(exist_ok=True)
file_path = save_dir / filename
with open(file_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
return {"error": False, "file_path": str(file_path)}
else:
return {"error": True, "message": response.text}
def delete(self, file_id: int) -> Dict[str, Any]:
"""Dosya sil"""
response = requests.delete(f"{self.base_url}/delete/{file_id}/",
headers=self.headers)
return response.json()
def list_files(self, category: str = None, search: str = None) -> Dict[str, Any]:
"""Dosyaları listele"""
params = {}
if category:
params['category'] = category
if search:
params['search'] = search
response = requests.get(f"{self.base_url}/list/",
headers=self.headers, params=params)
return response.json()
def get_info(self, file_id: int, password: str = None) -> Dict[str, Any]:
"""Dosya bilgilerini getir"""
params = {'password': password} if password else {}
response = requests.get(f"{self.base_url}/info/{file_id}/", params=params)
return response.json()
# Hızlı kullanım örneği
if __name__ == "__main__":
api = FileStorageAPI(api_key="SECURE_API_KEY")
# Dosya yükle
result = api.upload("test.txt", category="files",
description="Test dosyası")
print("Yükleme:", result)
# Dosyaları listele
files = api.list_files()
print("Dosya sayısı:", files['data']['total'] if not files.get('error') else 0)
# 1. Kütüphaneyi yükle
pip install requests
# 2. Kodu kaydet ve çalıştır
import requests
api_key = "SECURE_API_KEY"
headers = {'X-API-Key': api_key}
# Dosya yükle
with open("my_file.pdf", "rb") as f:
files = {'file': f}
data = {'category': 'files', 'description': 'İlk dosyam'}
response = requests.post("https://db.yakupkaya.me/api/upload/",
files=files, data=data, headers=headers)
result = response.json()
if not result.get('error'):
file_id = result['data']['file_id']
print(f"✅ Dosya yüklendi! ID: {file_id}")
# Dosyayı indir
download_response = requests.get(f"https://db.yakupkaya.me/api/download/{file_id}/")
if download_response.status_code == 200:
with open("downloaded_file.pdf", "wb") as f:
f.write(download_response.content)
print("✅ Dosya indirildi!")
else:
print(f"❌ Hata: {result['message']}")
Artık Python projelerinizde dosyalarınızı güvenli bir şekilde yönetebilirsiniz!