如何在Android中将图像上传到服务器?

前端之家收集整理的这篇文章主要介绍了如何在Android中将图像上传到服务器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试通过相机将图像捕获上传到服务器.服务器发送响应代码= 200但Image上传到服务器.

代码是:

  1. private boolean uploadData() {
  2. int count = this.forumThreadsB.size();
  3. for (int i = 0; i < count; i++)
  4. {
  5. if (isPhoto)
  6. message = "Uploading Shared Items " + (i + 1) + " of " + count;
  7. else
  8. message = "Uploading Shared Items " + (i + 1) + " of " + count;
  9. progressCount = (i * 1000)/count;
  10. HashtablesqliteForumDAO forumDAO = new sqliteForumDAO(mcontext) ;
  11. ForumThreadDTO forumThreadDTO = forumDAO.selectThread(this.threadid);
  12. if(downloadPath!=null && downloadPath.equalsIgnoreCase("null") && downloadPath.equalsIgnoreCase(""))
  13. forumThreadDTO.offlinefilepath = downloadPath;
  14. forumDAO.updateThread(forumThreadDTO);
  15. }
  16. } catch (IOException ioex) {
  17. Log.e("SyncUploadDownloadHelper","Upload file Failed: " + ioex.getMessage(),ioex);
  18. //return false;
  19. } catch (Exception e) {
  20. Log.e("SyncUploadDownloadHelper","Upload file Failed: " + e.getMessage(),e);
  21. //return false;
  22. }
  23. if (i == (this.forumThreadsB.size() - 1)){
  24. this.sendStatus = "true";
  25. progressCount = 1000;
  26. SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadDataFinish");
  27. }
  28. else
  29. SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadData");
  30. //return true;
  31. }
  32. return true;
  33. }

功能

  1. private String getBoundaryMessage(String boundary,Hashtable

在我的应用程序中我捕获图像并将其保存到数据库.保存图像的路径用于上传图像文件.

最佳答案
我用这个:

  1. public class HttpClient extends AsyncTask

代码使用该库:

  1. import org.apache.http.HttpEntity;
  2. import org.apache.http.HttpResponse;
  3. import org.apache.http.client.ClientProtocolException;
  4. import org.apache.http.client.methods.HttpPost;
  5. import org.apache.http.entity.mime.HttpMultipartMode;
  6. import org.apache.http.entity.mime.MultipartEntity;
  7. import org.apache.http.entity.mime.content.FileBody;
  8. import org.apache.http.impl.client.DefaultHttpClient;
  9. import org.apache.http.util.EntityUtils;
  10. import org.apache.james.mime4j.message.Message;

你可以在谷歌找到这个.如果你没找到 – 我可以发给你这个库.

猜你在找的Android相关文章