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

311
Vistas
How do I parse an image sent from Retrofit API from Android (multipart/form) in Python's Flask

I am sending my image as a part of Form Data through Retrofit API. There are no issues loading the image. I am trying to get this image in a Python Flask server.

My python code is not responding the expected way. I have tested my Python code with a JavaScript frontend application and the python server responds as expected. I believe the issue is parsing the multipart/form file which I receive from Android.

There are no network issues, I am able to log the requests. The detectFace() function is not responding as expected for the same image sent through both clients, VueJs and Android. Any ideas will be appreciated.

Here is the android code for uploading:

private void sendImageToServer() {
        File imageFile = loadImageFromStorage(tempImagePath);
        RequestBody reqBody = RequestBody.create(MediaType.parse("image/jpeg"), imageFile);
        MultipartBody.Part partImage = MultipartBody.Part.createFormData("file", "testImage", reqBody);
        API api = RetrofitClient.getInstance().getAPI();
        Call<TestResult> upload = api.uploadImage(partImage);
        upload.enqueue(new Callback<TestResult>() {
            @Override
            public void onResponse(Call<TestResult> call, Response<TestResult> response) {
                if(response.isSuccessful()) {
                    TestResult res = response.body();
                    String jsonRes = new Gson().toJson(response.body());
                    String result = res.getResult();
                    Log.v("REST22", result);
                }
            }

            @Override
            public void onFailure(Call<TestResult> call, Throwable t) {
                Log.v("REST22", t.toString());
                Toast.makeText(MainActivity.this, t.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

Here is Python code:

@app.route('/detectFaces/', methods=['POST'])
def detectFaces():
    img = request.files.get('file')
    print('LOG', request.files)
    groupName = 'random-group-03'
    result = face.detectFaces(img, groupName)
    print('RESULT', result)
    return {'result' : result[0]}

VueJs - alternate working frontend (REST client):

sendImage(img) {
      console.log(img)
      var form = new FormData();
      form.append('file', img, 'testImage')
      axios.post(this.baseUrl + 'detectFaces/?groupName=random-group-03', form)
      .then(res => {console.log(res.data); this.log = 'Detected face ids: \n ' + res.data.result});
    }
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