doukanxi4246 2014-04-21 07:28
浏览 94

如何将多个图像发送到服务器

My code is working for one image when I upload more then one image it show error to me .

Can anybody help me in getting out this problem?

Using below code I am able to upload single Image , but I want to upload more then one Image so please help how can I upload Images. Thanks

Here is my code

  String image_path=imageUrl1;
      GetData(myFiles);         

}


        });

}


public void GetData(String myFiles)
{

        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(myFiles);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream);
    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);


            }
         catch(final Exception e)
            {
                 runOnUiThread(new Runnable() 
                 {

                   @Override
                   public void run() 
                   {
                       Toast.makeText(PostAddActivity.this, "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show();                              
                   }
               });
                  System.out.println("Error in http connection "+e.toString());
            }  
   }
       });
   t.start();
    }
  • 写回答

1条回答 默认 最新

  • dongzhuo2010 2014-04-21 07:33
    关注

    To send more image in webservice. You have to change in webservice also. Add one more parameter in service part. so you can be able to send more than one image in one time.

    and get the base64 string of second image like e.g. img_str2

    like :

    String image_str = Base64.encodeBytes(byte_arr);
    String image_str2 = Base64.encodeBytes(byte_arr2);
    

    and named new parameter in service like image2

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

    Here image and image2 is 2 diff. parameter for images. these parameter names must also have to be define in your service side code.. so that service code can save your iamges.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大