我一直在尝试将图像和数据上传到Django服务器。我已经包含apache-mime4j.0.6.jar
和httpmime4.0.1.jar
库(项目->构建路径->添加外部 jar 文件)这是上传图像的代码。
HttpResponse response = null;
try {
HttpPost httppost = new HttpPost("http://10.0.2.2:8000/mobile");
// HttpPost httppost = new HttpPost("some url");
MultipartEntity multipartEntity = new MultipartEntity(); //MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("name", new StringBody("nameText"));
multipartEntity.addPart("place", new StringBody("placeText"));
multipartEntity.addPart("tag", new StringBody("tagText"));
//multipartEntity.addPart("Description", new StringBody(Settings.SHARE.TEXT));
multipartEntity.addPart("Image", new FileBody(destination));
httppost.setEntity(multipartEntity);
httpclient.execute(httppost, new PhotoUploadResponseHandler());
} catch (Exception e) {
Log.e( "Error","error");
}
错误信息:
Could not find class 'org.apache.http.entity.mime.MultipartEntity'
我已经尝试手动创建 libs 文件夹并手动将 jar 文件包含到 /libs 文件夹中。当我这样做时它无法编译。
错误:
Conversion to Dalvik format failed with error 1 Unknown Android Packaging Problem
尝试创建新的应用程序,包括库。我遇到了同样的错误。我已经尝试了所有可能的方法。谁能告诉我为什么会发生这种情况以及如何解决它。任何帮助将不胜感激!!