1
Я создал папку на моем IIS, здесь это адрес, что:Как загрузить картинку на сервер?
http://xxx.xxx.xx.120/checkin/Documents/
Я пытаюсь загрузить изображение на моем сервере .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");
}
}
http://stackoverflow.com/questions/19762581/how-to-take-a-photo-and-send-to-http-post-request-with-android/19762715#19762715 –
он всегда будет показывать загруженный файл, потому что вы сделали это в onPostExecute, несмотря на наличие ошибок на вашем сервере. опубликуйте свой код .NET, который обрабатывает почтовый запрос –