Я пытаюсь отправить несколько изображений в формате base64 с их exif-данными на сервер. При отправке только изображения у меня нет проблем, и все работает нормально, но когда я пытаюсь отправить несколько изображений, не важно, сколько выбранных изображений отправляет максимум два из них. ошибки нет, но я не могу найти свою ошибку. Любая помощь будет полезна заранее.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_CANCELED) {
return;
}
if (requestCode == GALLERY) {
if (data != null) {
// Get the Image from data
String[] filePathColumn = {MediaStore.Images.Media.DATA};
imagesEncodedList = new ArrayList<String>();
if (data.getData() != null) {
//this section gets the single image and works fine
} else {
if (data.getClipData() != null) {
ClipData mClipData = data.getClipData();
ArrayList<Uri> mArrayUri = new ArrayList<Uri>();
for (int i = 0; i < mClipData.getItemCount(); i++) {
ClipData.Item item = mClipData.getItemAt(i);
uri = item.getUri();
mArrayUri.add(uri);
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(uri, filePathColumn, null, null, null);
String path = null;
// SDK >= 11 && SDK < 19
if (Build.VERSION.SDK_INT < 19)
path = RealPathUtils.getRealPathFromURI_API11to18(getContext(), uri);
// SDK > 19 (Android 4.4)
else
path = RealPathUtils.getRealPathFromURI_API19(getContext(), uri);
Log.d(TAG, "File Path: " + path);
// Get the file instance
File file = new File(path);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imageEncoded = cursor.getString(columnIndex);
imagesEncodedList.add(imageEncoded);
cursor.close();
list.add(file.toString());
getExifData(path);
new SendImage().execute();
}
Log.v("LOG_TAG", "Selected Images" + mArrayUri.size());
}
}
// Uri uri = data.getParcelableExtra("path");
}
} else if (requestCode == CAMERA) {
if (data != null) {
//also this section works good
}
}
}
SendImage ()
public class SendImage extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
// showpDialog();
}
protected String doInBackground(String... arg0) {
try {
URL url = new URL("");
JSONObject postDataParams = new JSONObject();
postDataParams.put("user_id", user_id);
postDataParams.put("event_id", event_id);
postDataParams.put("img_loction_l", img_location_l);
postDataParams.put("img_loction_r", img_location_r);
postDataParams.put("images_file", ConvertImage);
postDataParams.put("img_time", img_time);
Log.e("params", postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new
InputStreamReader(
conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null) {
sb.append(line);
break;
}
in.close();
return sb.toString();
} else {
return new String("false : " + responseCode);
}
} catch (Exception e) {
return new String("Exception: " + e.getMessage());
}
}
@Override
protected void onPostExecute(String result) {
// hidepDialog();
try {
JSONObject jsonObject = new JSONObject(result);
String msg = jsonObject.getString("msg");//Your image has been Uploaded
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
// if (img_marker != null) {
// img_marker.remove();
// }
img_location_r = null;
img_location_l = null;
ConvertImage = null;
img_time = null;
img_gallery.setImageDrawable(null);
}
}
public String getPostDataString(JSONObject params) throws Exception {
StringBuilder result = new StringBuilder();
boolean first = true;
Iterator<String> itr = params.keys();
while (itr.hasNext()) {
String key = itr.next();
Object value = params.get(key);
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value.toString(), "UTF-8"));
}
return result.toString();
}