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

165
Views
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
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!