Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

661
Views
Cómo cambiar el nombre de un archivo subido con fastapi

Tengo un punto final que permite a los usuarios cargar archivos. Me gustaría cambiar el nombre del archivo a un nombre de archivo único y aleatorio, pero no sé cómo cambiar el nombre del archivo. Mi código actual es el siguiente, que está guardando el archivo en archivos/nombre de archivo

 @router.post('/qualifications/file') async def create_file(files: UploadFile = File(...)): file_location = f"files/{files.filename}" with open(file_location, "wb+") as file_object: file_object.write(files.file.read()) return {"info": f"file '{files.filename}' saved at '{file_location}'"}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¿Puedes generar una ubicación de archivo personalizada en lugar de usar files.filename ? Es posible que deba averiguar cuál era la extensión files.filename y pasarla al nuevo file_name que está creando.

 @router.post('/qualifications/file') async def create_file(files: UploadFile = File(...)):\ file_name = "some_random_name.txt" file_location = f"files/{file_name}" with open(file_location, "wb+") as file_object: file_object.write(files.file.read()) return {"info": f"file '{file_name}' saved at '{file_location}'"}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!