我有一个相机活动之后,我采取了一张照片,并保存到画廊和上传到服务器我的上传代码不工作,我需要在这方面的帮助?
//图像捕获
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();
}
最佳答案
这是一个很好的上传代码示例。它上传一个文件-正是你需要的How to send HTTP POST request and receive response?。
关于android - 使用HTTP协议(protocol)将位图上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3202627/