大佬教程收集整理的这篇文章主要介绍了如何在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;="">,?> threadd=""?>,?>)this.forumthreadsb.elementat(i); string="" onlinepath="http://xyx.com/;
threadid = (String) threadD.get(" devicethreadid");=""?>@H_489_14@sqliteForumDAO 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 stem.out.println(key + ": " + value);
res.append("Content-Disposition: form-data; name=\"").append(key).append("\"\r\n")
.append("\r\n").append(value).append("\r\n").append("--").append(boundary).append("\r\n");
}
res.append("Content-Disposition: form-data; name=\"").append("file").append("\"; filename=\"").append(fileName).append("\"\r\n")
.append("Content-Type: ").append(fileTypE).append("\r\n\r\n");
return res.toString();
}
public class httpClient extends AsyncTask multipartentity mpEntity = new multipartentity(
httpR_525_11845@ultipartMode.bROWSER_COMPATIBLE);
mpEntity.addPart("form_file",new FileBody(file,"image/jpeg"));
httppost.setEntity(mpEntity);
httpResponse response;
try {
response = httpclient.execute(httppost);
httpentity resEntity = response.getEntity();
if (resEntity != null) {
}
if (resEntity != null) {
resEntity.consumeContent();
}
} catch (ClientProtocolException E) {
e.printStackTrace();
} catch (IOException E) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(Long unused) {
progressDialog.dismiss();
((RunnablE) ctx ).run();
super.onPostExecute(unused);
}
protected void onPreExecute() {
progressDialog = new ProgressDialog(ctX);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setmessage("Загрузка фото...");
progressDialog.setProgress(0);
progressDialog.setMax(count);
progressDialog.show();
}
}
此代码使用该库:
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.httpR_525_11845@ultipartMode;
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;
你可以在谷歌找到这个.如果你没找到 – 我可以发给你这个库.
以上是大佬教程为你收集整理的如何在Android中将图像上传到服务器?全部内容,希望文章能够帮你解决如何在Android中将图像上传到服务器?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。