Android 如何在服务器上上传图像?

Android 如何在服务器上上传图像?,android,server,image-uploading,image-upload,Android,Server,Image Uploading,Image Upload,我已在我的IIS上创建文件夹,以下是该文件夹的url: 我正在尝试在.NET服务器上上载图像,但不幸没有成功。我不知道出了什么问题,上面说文件上传了,但当我检查服务器时,它显示的是空文件夹。这是我的密码 class ImageUploadTask extends AsyncTask<Void, Void, String> { private String webAddressToPost = "http://xxx.xxx.xx.120/checkin/Documents/";

我已在我的IIS上创建文件夹,以下是该文件夹的url:

我正在尝试在.NET服务器上上载图像,但不幸没有成功。我不知道出了什么问题,上面说文件上传了,但当我检查服务器时,它显示的是空文件夹。这是我的密码

 class ImageUploadTask extends AsyncTask<Void, Void, String> {
  private String webAddressToPost = "http://xxx.xxx.xx.120/checkin/Documents/";

  // private ProgressDialog dialog;
  private ProgressDialog dialog = new ProgressDialog(ImageGalleryDemoActivity.this);

  @Override
  protected void onPreExecute() {
   dialog.setMessage("Uploading...");
   dialog.show();
  }

  @Override
  protected String doInBackground(Void... params) {
   try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpPost httpPost = new HttpPost(webAddressToPost);

    MultipartEntity entity = new MultipartEntity(
      HttpMultipartMode.BROWSER_COMPATIBLE);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 100, bos);
    byte[] data = bos.toByteArray();
    String file = Base64.encodeBytes(data);
    entity.addPart("uploaded", new StringBody(file));

    entity.addPart("someOtherStringToSend", new StringBody("your string here"));

    httpPost.setEntity(entity);
    HttpResponse response = httpClient.execute(httpPost,
      localContext);
    BufferedReader reader = new BufferedReader(
      new InputStreamReader(
        response.getEntity().getContent(), "UTF-8"));

    String sResponse = reader.toString();
    System.out.println("PPPPPPPPPPPPP>>>>>>>>>> " + sResponse);
    return sResponse;
   } catch (Exception e) {
    // something went wrong. connection with the server error
       System.out.println(">>>?????? " + e.getMessage());
   }
   return null;
  }

  @Override
  protected void onPostExecute(String result) {
   dialog.dismiss();
   Toast.makeText(getApplicationContext(), "file uploaded",
     Toast.LENGTH_LONG).show();
   new DownloadImage().execute("http://xxx.xxx.xx.120/checkin/Documents/abc.jpg");
  }

 }
你可以在广场上用。这是一个非常好的图书馆


它将始终显示上载的文件,因为无论服务器中是否有错误,都是您在onPostExecute中执行的。也发布处理post请求的.NET代码