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

920
Views
Flask send_file as attachment the file download but ajax success function has no response

I'm creating a YouTube Video Downloader for which I use flask for the backend. I send an ajax request to the flask in return a flask return file which by default set to download. The file starts downloading but the problem is that there is no responseText or statusCode in the success function in ajax
Ajax Function which I used to work in the same way as jquery ajax does
My Ajax code is

    let formData = new FormData(downloadform);
    ajax({
      url: '/download',
      method: "POST",
      data: formData,
      onprogress: () => {
        download_loadingBtn.style.display = "block";
        downloadBtn.style.display = "none";
      },
      onsuccess: (responseText, status, statusText) => {
        download_loadingBtn.style.display = "none";
        downloadBtn.style.display = "block";
        console.log(responseText, status, statusText);
      },
      onfailure: (status, statusText) =>{
        console.log(status, statusText);
      }
    })

My Flask code is

@app.route("/download", methods = ["GET", "POST"])
def download_video():
    if request.method == "POST":
        buffer = BytesIO()
        url = YouTube(session['link'])
        itag = request.form.get("itag")
        video = url.streams.get_by_itag(itag)
        video.stream_to_buffer(buffer)
        buffer.seek(0)
        return send_file(buffer, as_attachment=True, download_name=url.title, mimetype="video/mp4") 

I also tried to return an object with some response text and send_file() such as

return jsonify({
       "text": "successfully downloaded",
       "download_file": send_file(buffer, as_attachment=True, download_name=url.title, mimetype="video/mp4") 
})

but that also gives an error i.e. TypeError: Object of type Response is not JSON serializable

over 4 years ago · Santiago Trujillo
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!