private void uploadMapToServer(RoomMap newMap) { Mongo mongo = null; DB database; DBCollection sampleData; String databaseAddress = DEFAULT_DATABASE_ADDRESS; try { // read parameters from the configuration file databaseAddress = Utilities.getConfigurationValue(DATABASE_ADDRESS); } catch (NumberFormatException exception) { // reading has failed, use default values logger.info( "Reading parameters from configuration file failed. " + "Using default values for database_address instead."); } try { mongo = new Mongo(databaseAddress); } catch (UnknownHostException e1) { e1.printStackTrace(); } database = mongo.getDB("rssiSystem"); sampleData = database.getCollection("map_records"); // remove all maps sampleData.drop(); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String strDate = simpledateformat.format(new Date()); // ------------------- // Load our image byte[] imageBytes = null; try { imageBytes = Utilities.LoadImageAsBytes(newMap.getPath()); } catch (Exception e1) { e1.printStackTrace(); } // --------------------- // Create GridFS object GridFS fs = new GridFS(database); // Save image into database GridFSInputFile in = fs.createFile(imageBytes); in.save(); Object mapIdObject = in.getId(); // System.out.println(mapIdObject); try { DBObject documentDetail = new BasicDBObject(); documentDetail.put("_cls", "mapRecords"); // for mongoEngine ORM users documentDetail.put("image", mapIdObject); documentDetail.put("mapId", newMap.getId()); documentDetail.put("width", newMap.getWidthInMeters()); documentDetail.put("height", newMap.getHeightInMeters()); documentDetail.put("offsetX", newMap.getLowerLeftMarkerOffsetXInPixels()); documentDetail.put("offsetY", newMap.getLowerLeftMarkerOffsetYInPixels()); documentDetail.put("offset2X", newMap.getUpperRightMarkerOffsetXInPixels()); documentDetail.put("offset2Y", newMap.getUpperRightMarkerOffsetYInPixels()); documentDetail.put("scalingX", newMap.getRatioWidth()); documentDetail.put("scalingY", newMap.getRatioHeight()); documentDetail.put("title", newMap.getTitle()); documentDetail.put("updateTime", strDate); sampleData.insert(documentDetail); } catch (Exception e) { e.printStackTrace(); } }