이미지 업로드 코드인데...
갤러리에서 이미지를 선택하면 서버로 보내기만 하면 되는 간단한 코드입니다.
컴파일 에러는 안나는데 실제로 전송이 ㅇ안되네요 ㅠㅠ .... 한번만 굽어 살펴주세요 ㅠㅠ
사진 선택하는 부분
tv = (TextView)findViewById(R.id.textView1);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, TAKE_PICTURE);
}
});
여기서부터 보시면 될 듯 합니다.. ㅠㅠㅠ
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == TAKE_PICTURE){
if( data != null ){
//final Bundle extras = data.getExtras();
//Bitmap photo = extras.getParcelable("data");
Uri selPhotoUri = data.getData();
try{
Bitmap selPhoto = Images.Media.getBitmap(getContentResolver(),selPhotoUri);
Cursor c = getContentResolver().query(Uri.parse(selPhotoUri.toString()), null, null, null, null);
c.moveToFirst();
abPath = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
setAbPath(abPath);
timeThread();
c.close();
if( selPhoto != null ){ // 가지고온 사진 데이터를 이미지 뷰에 보여 준다.
iv.setImageBitmap(selPhoto);
tv.setText(abPath.toString());
//signup_camera.setImageBitmap(photo);
//Uri currImageURI = data.getData();
//textView.setText("GALLERY : " + getRealPathFromURI(currImageURI));
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
public String getAbPath(){
return abPath;
}
public void timeThread() {
dialog = new ProgressDialog(this);
dialog = new ProgressDialog(this);
dialog.setTitle("Wait...");
dialog.setMessage("사진 전송 중");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
fileupload();
} catch (Exception e) {
Log.e("error", e.getMessage(), e);
}
dialog.dismiss();
}
private void sleep(int i) {
// TODO Auto-generated method stub
}
}).start();
}
public void fileupload(){
try {
File file = new File(getAbPath());
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlString);
post.setHeader("Connection", "Keep-Alive");
post.setHeader("Accept-Charset", "euc-kr");
post.setHeader("ENCTYPE", "multipart/form-data");
FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("MEM_image", bin);
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("RESPONSE", EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
}
고수님들 한번만 부탁드립니다. ㅠㅠ