我一直在尝试将图像和数据上传到 Django 服务器。我包含了 apache-mime4j.0.6.jar
和 httpmime4.0.1.jar
库(Project->build path->Add external jar files)
这是上传图片的代码。
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
尝试创建包括库在内的全新应用程序。我遇到了同样的错误。我已经尝试了所有可能的方法。任何人都可以告诉我为什么会发生这种情况以及如何解决它。任何帮助将不胜感激!!
最佳答案
如果你正在使用新的 android-sdk
试试这个。
- 创建名为
libs
的文件夹 - 将您的 jar 文件粘贴到该文件夹中。
- 最后右键单击您的项目 > Build Path > Add External Archive。
就是这样。这可能会有所帮助。祝你好运。
关于Android 使用 MultipartEntity 将图像发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13190009/