Ich versuche, das aufgenommene Foto auf den Server hochzuladen. das ist was ich mache:
public JSONObject makePostFileRequest(String url, String photoFile) {
try {
// photoFile = /path/tofile/pic.jpg
DefaultHttpClient httpClient = GlobalData.httpClient;
HttpPost httpPost = new HttpPost(url);
File file = new File(photoFile);
FileBody fileBody = new FileBody(file); // here is line 221
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("PhotoMessage", fileBody);
httpPost.setEntity(multipartEntity.build());
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
Ich bekomme diesen Fehler:
11-29 13:12:14.924: E/AndroidRuntime(15781): Verursacht durch: java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType 11-29 13:12:14.924: E/AndroidRuntime(15781): at org.apache.http.entity.mime.content.FileBody.(FileBody.java:89) 11-29 13:12:14.924: E/AndroidRuntime(15781): at com.petcial.petopen.custom.JSONParser.makePostFileRequest (JSONParser.java:221)
Was mache ich falsch?
Aktualisieren
InputStream inputStream;
inputStream = new FileInputStream(new File(photoFile));
byte[] data;
data = IOUtils.toByteArray(inputStream);
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
System.getProperty("http.agent"));
InputStreamBody inputStreamBody = new InputStreamBody(new ByteArrayInputStream(data), "Pic.jpg");
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("PhotoMessage", inputStreamBody);
httpPost.setEntity(multipartEntity.build());
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
hier ist der fehler:
11-29 14:00:33.364: E/AndroidRuntime(19478): Verursacht durch: java.lang.NoClassDefFoundError: org.apache.http.util.Args 11-29 14:00:33.364: E/AndroidRuntime(19478): at org.apache.http.entity.mime.content.AbstractContentBody.(AbstractContentBody.java:48) 11-29 14:00:33.364: E/AndroidRuntime(19478): at org.apache.http.entity.mime.content .InputStreamBody.(InputStreamBody.java:69) 11-29 14:00:33.364: E/AndroidRuntime(19478): at org.apache.http.entity.mime.content.InputStreamBody.(InputStreamBody.java:62) 11- 29 14:00:33.364: E/AndroidRuntime(19478): at com.petcial.petopen.custom.JSONParser.makePostFileRequest(JSONParser.java:233)
Diese Bibliotheken haben mein Problem gelöst:
FileBody
gehört nicht zur Standard-Android-Bibliothek. Welches Gefäß verwendest du?– gunar
29. November ’13 um 11:20
Hast du httpmime-4.3.jar im Projekt hinzugefügt?
– Ich freue mich auf
29. November ’13 um 11:22
Natürlich. im libs-Ordner
– Filip Luchianenco
29. November ’13 um 11:23
Welche IDE verwendest du? Finsternis? Wenn ja, stellen Sie sicher, dass es hinzugefügt und exportiert wurde, wie in dieser Antwort
– gunar
29. November ’13 um 11:23
Hi, @FilipLuch hast du eine Lösung für dieses Problem gefunden?
– farrukh
24. Februar ’15 um 23:23