我正在尝试通过相机将图像捕获上传到服务器.服务器发送响应代码= 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;
Hashtable,?> threadD = (Hashtable,?>)this.forumThreadsB.elementAt(i);
String onlinePath = "http://xyx.com/;
threadid = (String) threadD.get("devicethreadid");
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
最佳答案
我用这个:
原文链接:https://www.f2er.com/android/430531.htmlpublic 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;
你可以在谷歌找到这个.如果你没找到 – 我可以发给你这个库.