多个图像发送到服务器

时间:2014-04-18 12:20:02

标签: android image http bitmap multiprocessing

当我上传单个图片到服务器代码工作正常, 当我上传两个图像作为字符串时,它显示空指针异常。 任何人都可以帮助我将两个或更多图像发送到服务器。 谢谢 这是上传图片的代码

            String image_path=imageUrl1+","+imageUrl2;

           GetData(image_path);


        }
        });

}


public void GetData(String image_path)
{

        String image_retrive_url="http://tradewale.com/open/tradedata.php?submitType=PostAd";

        pDialog = new ProgressDialog(PostAddActivity.this);
        pDialog.setMessage(" Sending...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();


    Bitmap bitmap = BitmapFactory.decodeFile(image_path);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream); //compress to which format you want.
    byte [] byte_arr = stream.toByteArray();
    String image_str = Base64.encodeBytes(byte_arr);
    final ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();

    String Title = title.getText().toString();
    String Description = description.getText().toString().trim();
    String PhoneNumber = phonenumber.getText().toString();
    String Email = email.getText().toString();
    String Price = price.getText().toString();


    nameValuePairs.add(new BasicNameValuePair("image",image_str));

    nameValuePairs.add(new BasicNameValuePair("photo_url", image_retrive_url));



    Thread t = new Thread(new Runnable() 
    {

   @Override
   public void run() {
         try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://tradewale.com/open/tradedata.php?submitType=PostAd");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                final String the_string_response = convertResponseToString(response);


            }

0 个答案:

没有答案