ANDROID发送图像并保存网址 [英] Android send a image and save url

查看:173
本文介绍了ANDROID发送图像并保存网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  发送POST数据的android

如何通过HTTP POST随着表单数据即映像名称发送图像等

How to send a image via http post along with the form data i.e image name etc

到指定的URL ..这是URL中的 ASPX

to a specified url .. which is the url of a aspx.

推荐答案

勾选此code与标题发送图片,标题,名称等,

Check this code for Sending Image with Title,Caption,Name etc,

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost("You Link");
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    reqEntity.addPart("name", new StringBody("Name"));
    reqEntity.addPart("Id", new StringBody("ID"));
    reqEntity.addPart("title",new StringBody("TITLE"));
    reqEntity.addPart("caption", new StringBody("Caption"));
    try{
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 75, bos);
        byte[] data = bos.toByteArray();
        ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
        reqEntity.addPart("picture", bab);
    }
    catch(Exception e){
        //Log.v("Exception in Image", ""+e);
        reqEntity.addPart("picture", new StringBody(""));
    }
    postRequest.setEntity(reqEntity);       
    HttpResponse response = httpClient.execute(postRequest);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String sResponse;
    StringBuilder s = new StringBuilder();
    while ((sResponse = reader.readLine()) != null) {
        s = s.append(sResponse);
    }

其中位图图像位图。

Where bitmap is the Image Bitmap.

让我知道如果你发现任何问题。

Let me know if you find any difficulty.

由于Venky。

这篇关于ANDROID发送图像并保存网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆