カメラで撮影した画像をサーバーにアップロードするアプリを取得しようとしています。問題なく完全に問題なくURLにアクセスできるため、サーバーではないことはわかっています。私はError in http connection android.os.NetworkOnMainThreadException
エラーとして取得しています。これが私が使用しようとしているコードです。
public void uploadFile(Bitmap file) {
Bitmap bitmapOrg = file;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte[] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.info/appserver/upload.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}