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

332
Vistas
How to send Image from FLASK to JavaScript (JSON)?
function classifyWaste(){
  var file = document.getElementById("file").files;
  if(file.length > 0){
    var form_data = new FormData();
    form_data.append("file", document.getElementById("file").files[0]);
    $.ajax({
      url: 'classifywaste', // point to server-side URL
      dataType: 'json', // what to expect back from server
      cache: false,
      contentType: false,
      processData: false,
      data: form_data,
      type: 'post',
      success: function (data) {
        var response = response["response"];

// I want to receive returned file from classifywaste() (app.py)

      document.getElementById("image_to_replace").setAttribute("src", "SOME_IMAGE_FILE");
      }

    });
  }

I found a way to do it by encoding with base64 but could not implement it clearly. So, how can I encode the image in base64 from the flask and return its string, and then decode it from the javaScript file to post in the frontend?

@application.route("/classifywaste", methods=["POST"])
def classifywaste():
    image_data = request.files["file"]
....
// Image received and performed other actions

// lets say, I have received image file after classifying 
    image_file_after = util.classify_waste(image_path)

// Here, I want to return image file to the classifyWaste() in .js file

    return jsonify(response=response)

Can you lay down the code for base64 for this case? Thanks!

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