Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
RestAPI unable to download a file sent from Django API to sveltekit client - Fatal error reading a PNG image file

I have a Django Get APIView which returns a FileResponse with a png image data. When it is downloaded on the sveltekit client side then its not being read. It complains that it is not a png file. Not sure what is wrong. Here is the server code:

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

I have commented all the possibilities that I tried. Now here is the client side code:

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();
        // });
    }

Thank you for help and comments.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda