title: Error While Uploading Image to server using PHP
body: <p>I'm trying to upload an image to a server by using php. But I'm getting following error:</p>
  
  <blockquote>
  Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 171:my server name/upload.php?sel_bar_code=ab12&text=hello&image=[encoded image to base64 comes hear]</blockquote>
  
  <p>I'm not getting this error on android. Below is my code that uploades images to the server.</p>
  
  <pre><code>if (isImage) {
              imgPreview.setVisibility(View.VISIBLE);
              vidPreview.setVisibility(View.GONE);
              // bimatp factory
              BitmapFactory.Options options = new BitmapFactory.Options();
  
              // down sizing image as it throws OutOfMemory Exception for larger
              // images
              options.inSampleSize = 8;
  
              bitmap = BitmapFactory.decodeFile(filePath, options);
              imgPreview.setImageBitmap(bitmap);
  
              ByteArrayOutputStream ByteStream=new  ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.PNG,100, ByteStream);
              byte [] b=ByteStream.toByteArray();
              image_value=Base64.encodeToString(b, Base64.DEFAULT);
  </code></pre>
  
  <p>Background process code:</p>
  
  <pre><code>protected String doInBackground(Void... params) {
              return uploadFile();
          }
  
          @SuppressWarnings("deprecation")
          private String uploadFile() {
              String responseString = null;
  
              HttpClient httpclient = new DefaultHttpClient();
              List&lt;NameValuePair&gt; qparams = new ArrayList&lt;NameValuePair&gt;();
           // These params should ordered in key
              qparams.add(new BasicNameValuePair("sel_bar_code", product_id));
  
              HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL+"sel_bar_code="+product_id+"&amp;text="+text_value +"&amp;image="+image_value);
  
              try {
                  AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                          new ProgressListener() {
  
                              @Override
                              public void transferred(long num) {
                                  publishProgress((int) ((num / (float) totalSize) * 100));
                              }
                          });
  
                  File sourceFile = new File(filePath);
  
                  // Adding file data to http body
                  entity.addPart("image", new FileBody(sourceFile));
  
                  // Extra parameters if you want to pass to server
                  entity.addPart("website",
                          new StringBody("www.google.com"));
                  entity.addPart("email", new StringBody("info@gmail.com"));
  
                  totalSize = entity.getContentLength();
                  httppost.setEntity(entity);
  
                  // Making server call
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity r_entity = response.getEntity();
  
                  int statusCode = response.getStatusLine().getStatusCode();
                  if (statusCode == 200) {
                      // Server response
                      responseString = EntityUtils.toString(r_entity);
                  } else {
                      responseString = "Error occurred! Http Status Code: "
                              + statusCode;
                  }
  
              } catch (ClientProtocolException e) {
                  responseString = e.toString();
              } catch (IOException e) {
                  responseString = e.toString();
              }
  
              return responseString;
  
          }
  </code></pre>