Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda