Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(cursor.getCount() > 0) {
- cursor.moveToFirst();
- while (!cursor.isAfterLast()) {
- reqEntity.addPart(configuration.S_RECORD_USER_ID, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_USER_ID)));
- reqEntity.addPart(configuration.S_RECORD_FORM_ID, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_FORM_ID)));
- reqEntity.addPart(configuration.S_RECORD_JSON_DATA, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_JSON_DATA)));
- reqEntity.addPart(configuration.S_LATITUDE, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_LATITUDE)));
- reqEntity.addPart(configuration.S_LONGITUDE, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_LONGITUDE)));
- reqEntity.addPart(configuration.S_CREATED_AT, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_CREATED_AT)));
- reqEntity.addPart(configuration.S_LAST_UPDATE, cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_LAST_UPDATE)));
- // proccess image here
- jsonObject = new JSONObject(cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_JSON_IMAGE)));
- Log.d("COBAIN", jsonObject.toString());
- if(jsonObject != null){
- jsonArray = jsonObject.getJSONArray("form_values_image");
- // loop through array length
- for(int i = 0; i < jsonArray.length(); i++){
- jsonObject = jsonArray.getJSONObject(i);
- // count the json object length here
- if(jsonObject.length() > 0){
- // loop through json object to convert img path to byte
- for(int j = 0; j < jsonObject.length(); j++){
- Log.d("PATH", jsonObject.getString("image_path_" + j));
- photoToSend = processImage.decodeSampledBitmapFromFile(jsonObject.getString("image_path_" + i), 480, 480);
- stream = new ByteArrayOutputStream();
- photoToSend.compress(Bitmap.CompressFormat.PNG, 100, stream);
- inputStream = new ByteArrayInputStream(stream.toByteArray());
- // image name format : created_date_formid.png
- reqEntity.addPart("myFile", cursor.getString(cursor.getColumnIndex(SQLiteHelper.RECORD_CREATED_AT)).replace(":", "") + "_" + extras.getStringExtra("FORM_ID") + ".png", inputStream);
- }
- }
- }
- }
- httppost.setEntity(reqEntity);
- response = null;
- try {
- // begin post image to server
- response = httpclient.execute(httppost);
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- if (response != null) {
- if (response.getStatusLine().toString().equals("HTTP/1.1 200 OK")) {
- try {
- HttpEntity httpEntity = response.getEntity();
- inputStream = httpEntity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- inputStream, "ISO-8859-1"), 8);
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- inputStream.close();
- Log.d("JSONParser", sb.toString());
- } catch (Exception e) {
- Log.e("Buffer Error", "Error converting result " + e.toString());
- }
- }
- Log.i("SERVER RESPONSE STATUS", response.getStatusLine().toString());
- }
- } finally {
- }
- cursor.moveToNext();
- }
- cursor.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment