Sending a file and a string using MultiPartEntity in Android to server

97 Views Asked by At

I have an Android app from which I can select a video and select an option from a drop down. I want to send both of these to the server for analysis and get back the results. This is the code.

Android app

MultiPartEntity entity = new MultiPartEntity (); entity.addPart("option", new StringBody(selectedOption)); entity.addPart("file", new FileBody(sourceFile));

httppost.setEntity(entity); HttpResponse response = httpclient.execute(httppost);

Server code

if request.method == 'POST': if 'option' not in request.files: return 'No option selected'

On the server, when I get a POST request, I'm checking whether 'file' and 'option' are present. But I find only file is present and not the option. What am I missing out here?

0

There are 0 best solutions below