2010-07-08 81 views
2

我有一個相機活動之後,我拍照並將其保存到圖庫並上傳到服務器我的上傳代碼不工作,我需要幫助嗎?使用http協議將位圖上傳到服務器

//圖像採集

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
startActivityForResult(intent, 0); 

//圖像保存

if(requestCode==0&&resultCode==RESULT_OK) 

{ 

    Bundle extras = data.getExtras(); 
    Bitmap b = (Bitmap) extras.get("data"); 

    ImageView mImg; 
    mImg = (ImageView) findViewById(R.id.head); 
    mImg.setImageBitmap(b); 

    // save image to gallery 
    Shot = "HeadShot"; //Long.toString(System.currentTimeMillis()); 
    MediaStore.Images.Media.insertImage(getContentResolver(), b, Shot, NAME); 

} 

//上傳到服務器

public void Upload(String url, HttpEntity imgdata) throws Exception, Exception { 

    DefaultHttpClient client = new DefaultHttpClient(); 
    HttpPost post = new HttpPost(url); 
    post.setHeader("Content-Type", "bitmap; charset=utf-8"); 
    post.setURI(new URI(url)); 
    post.setEntity(imgdata); 
    HttpUriRequest request = post; 
    HttpResponse response = client.execute(request); 
    HttpEntity entity = response.getEntity(); 
    return entity.getContent(); 
} 
+0

究竟不起作用?錯誤是什麼? – Fedor 2010-07-08 10:30:23

+0

//上傳到服務器 – 2010-07-08 10:40:38

+0

我不知道如何上傳保存在圖庫中的那個filw,請告訴我怎樣才能上傳它 – 2010-07-08 10:48:33

回答

相關問題