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

320
Views
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
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!