我正在尝试将图像上传到 webService,但我做不到,我在这里和互联网上搜索了很多主题,但找不到好的解决方案。
当我运行此代码时,我收到错误请求错误。
更新:我使用了此链接中的一些代码:Uploading MS Word files from Android to .Net WCF?
但是给我FileNotFoundException,但我的文件路径是:/mnt/sdcard/ImageDir/images/ilan_1360917248037__thumb_.jpeg
这是我正在尝试的代码:
public static String imgUpload(String url, List<NameValuePair> list, List<String> images){
String result = Constants.EMPTY;
Bitmap bm;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, ServiceConstant.TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, ServiceConstant.TIMEOUT_MILLISEC);
HttpParams p = new BasicHttpParams();
HttpClient httpclient = new DefaultHttpClient(p);
HttpPost httppost = new HttpPost(url);
String resimYol = images.get(0);
resimYol = resimYol.replace("file:///", "/");
bm = BitmapFactory.decodeFile(resimYol);
Log.d("RESIL_YOL", resimYol.toString());
try{
ByteArrayBody bab = new ByteArrayBody(b, resimYol);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(data, resimYol);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
httppost.setEntity(reqEntity);
result = httpclient.execute(httppost,responseHandler);
}
catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());
}
return result;
}
这是我的日志:
02-12 11:43:07.467: E/org.apache.http.client.HttpResponseException(19112): Bad Request