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

160
Views
RestAPI no puede descargar un archivo enviado desde Django API al cliente sveltekit - Error fatal al leer un archivo de imagen PNG

Tengo un Django Get APIView que devuelve un FileResponse con datos de imagen png. Cuando se descarga en el lado del cliente sveltekit, no se lee. Se queja de que no es un archivo png. No estoy seguro de qué está mal. Aquí está el código del servidor:

 from django.http import FileResponse, HttpResponse import mimetypes # from django.core.files import File mime_type, _ = mimetypes.guess_type('qrcode.png') response = HttpResponse(open('qrcode.png', 'rb'), content_type=mime_type) # response = FileResponse(open('qrcode.png', 'rb'), content_type=mime_type) # response = HttpResponse(open('qrcode.png', 'rb')) # response = HttpResponse(open('qrcode.png', 'rb'), content_type='application/png') # response = HttpResponse(FileWrapper(img), content_type='application/png') response['Content-Disposition'] = 'attachment; filename=qrcode.png' return response

He comentado todas las posibilidades que probé. Ahora aquí está el código del lado del cliente:

 if (res.status == 200){ qrimage = await res.data; console.log(typeof(qrimage)); // const blob = new Blob(qrimage); // let url = window.URL.createObjectURL(blob); // let url = window.URL.createObjectURL(qrimage); let a = document.createElement("a"); // console.log(url); a.href = 'data:image/png;'+qrimage; a.target = '_blank'; a.download = 'qrcode.png'; a.click(); // }); }

Gracias por la ayuda y los comentarios.

about 4 years ago · Juan Pablo Isaza
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!