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

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

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

代码是:

private boolean uploadData() {

    int count = this.forumThreadsB.size();
    for (int i = 0; i < count; i++)
    {
            if (isPhoto)
                message = "Uploading Shared Items " + (i + 1) + " of " + count;
            else
                message = "Uploading Shared Items " + (i + 1) + " of " + count;

            progressCount = (i * 1000)/count; 
            HashtablesqliteForumDAO forumDAO = new sqliteForumDAO(mcontext) ;
                            ForumThreadDTO forumThreadDTO = forumDAO.selectThread(this.threadid);
                            if(downloadPath!=null && downloadPath.equalsIgnoreCase("null") && downloadPath.equalsIgnoreCase(""))
                            forumThreadDTO.offlinefilepath = downloadPath;
                            forumDAO.updateThread(forumThreadDTO);


                    }


                } catch (IOException ioex) {
                    Log.e("SyncUploadDownloadHelper","Upload file Failed: " + ioex.getMessage(),ioex);
                    //return false;
                } catch (Exception e) {
                    Log.e("SyncUploadDownloadHelper","Upload file Failed: " + e.getMessage(),e);
                    //return false;
                }

                if (i == (this.forumThreadsB.size() - 1)){
                    this.sendStatus = "true";
                    progressCount = 1000;
                    SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadDataFinish");
                }
                else
                    SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadData");

                //return true;

    }

    return true;
}

功能

private String getBoundaryMessage(String boundary,Hashtable

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

最佳答案
我用这个:

public class HttpClient extends AsyncTask

代码使用该库:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.james.mime4j.message.Message;

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

原文链接:https://www.f2er.com/android/430531.html

猜你在找的Android相关文章