Как загрузить данные формы и изображения из нескольких частей на сервер в Android?
Код состояния 500 во время загрузки изображения из нескольких частей сущности на сервер в код Android
HTML-форма: (можете успешно добавить изображение на сервер)
Sample Picture Upload Form Submit
<br><br>
API key: <br><br>
Login: <br>
Password: <br><br>
Property ID:<br>
Picture File:<br><br>
<br><br>
<br>
Код Android: (дает код состояния 500)
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://xyz/upload_picture");
try {
MultipartEntity entity = new MultipartEntity();
entity.addPart("key", new StringBody("abc"));
entity.addPart("login", new StringBody("abc"));
entity.addPart("password", new StringBody("test"));
entity.addPart("property_id", new StringBody("111"));
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM).toString()
+ "/Camera/Test.jpg");
entity.addPart("picture", new FileBody(file));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
Log.e("test", "SC:" + response.getStatusLine().getStatusCode());
HttpEntity resEntity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.e("test", "Response: " + s);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}