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

914
Vistas
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
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