Add new file

parent 76994f56
import requests
from pathlib import Path
import sys
# -- CONFIG ---------------------------------------------
KADI_URL = "https://192.168.128.44/api/biaprint/folder"
TOKEN = "pat_ef2df043911631d9c43d4e9846062843c8708e44925b55f3" # Cambiar token cuando cambies el usuario
# Carpeta a enviar (puedes pasarla como argumento)
FOLDER = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("/home/pi/session")
# -- VALIDACIONES ---------------------------------------
if not FOLDER.exists() or not FOLDER.is_dir():
print(f" Carpeta no valida: {FOLDER}")
sys.exit(1)
# -- PREPARAR FILES -------------------------------------
files = []
for p in FOLDER.rglob("*"):
if p.is_file():
rel_path = p.relative_to(FOLDER)
files.append(
("files[]", (str(rel_path), open(p, "rb")))
)
print(f" Enviando {len(files)} archivos desde {FOLDER}...")
# -- REQUEST --------------------------------------------
try:
response = requests.post(
KADI_URL,
headers={
"Authorization": f"Bearer {TOKEN}"
},
data={
"folder_name": FOLDER.name
},
files=files,
verify=False # pon True si usas HTTPS valido
)
print(f" Status: {response.status_code}")
try:
print(" Respuesta JSON:")
print(response.json())
except Exception:
print(" Respuesta texto:")
print(response.text)
except Exception as e:
print(f" Error enviando datos: {e}")
finally:
# cerrar archivos
for _, (_, f) in files:
f.close()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment