나는 안드로이드에서 PHP 서버로 이미지를 업로드하는 앱을 만들고 PHP 서버는 요청에 대한 응답으로 URL을 반환합니다. 나는 아이폰을 위해 잘 작동하는 PHP 서버 측에서 아무 문제도 체크하지 않았다. 하지만 안드로이드에서 나는 응답을 얻을 수 없습니다. 내 이미지가 업로드되지 않은 PHP 서버를 확인했습니다. 나는 코드의 문제점과 응답을 얻는 방법을 모른다. 필요한 설정이 있습니까? 내 코드 :이미지가 PHP 서버에 업로드되지 않았습니다. android에서 servre의 응답이 없습니다
public class upload extends Activity {
InputStream is;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Bitmap bitmapOrg = BitmapFactory.decodeFile("/sdcard/imageq.png");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.PNG, 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://xxxxxxxxxx/xxxxxx/upload.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("uri",""+httppost.getURI());
Log.e("response",""+response);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("is",""+is);
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
}
나는 http://blog.sptechnolab.com/2011/03/09/android/android-upload-image-to-server/ 내 로그 고양이 정보에서 위의 코드를 얻을 :
05-11 10:09:39.488: ERROR/uri(1894): http://xxxxxxxxxx/xxxxxx/upload.php
05-11 10:09:39.488: ERROR/response(1894): [email protected]
05-11 10:09:39.495: ERROR/is(1894): [email protected]
내가 getURI 그것이 내가 httppost = 새로운 HttpPost에주고 무엇을 반환 인쇄 ("... "). 이것은 서버로부터의 실제 응답이 아닙니다. 도와주세요.
저는 그것을 구현합니다. 하지만 난 'serverImageTag'과 uploadImageData 함수가 호출되는 곳이 무엇인지 의심 스럽다. –
uploadImageData이 함수 호출은 FileUploader 클래스의 객체를 생성 한 직후에 호출되며 serverImageTag는 함수 및 조건에 대해 제거 할 필요가없는 경우 PHP 서버에서 제공 한 태그입니다. – DynamicMind