boolean uploadPicture(Picture p) { try { //transferListener.currentFile = p.toString(); status(su, StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "upPrep")); MultipartEntity entity = new MultipartEntity(); Charset utf8 = Charset.forName("UTF-8"); JSONObject jsonEntity = new JSONObject(); jsonEntity.put("type", "photo"); if (p.getName() != null) jsonEntity.put("name", p.getName()); if (p.getTitle() != null) jsonEntity.put("title", p.getTitle()); if (p.getDescription() != null) jsonEntity.put("description", p.getDescription()); entity.addPart("entity", new StringBody(jsonEntity.toJSONString(), utf8)); ContentBody body = new FileBody(p.getUploadSource()); entity.addPart("file", body); BufferedReader entityReader = sendRequest(p.getParentAlbum().getUrl(), "post", entity); String url = ((JSONObject) JSONValue.parse(entityReader)).get("url").toString(); status(su, StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "upSucc")); p.setUrl(url); Log.log(Log.LEVEL_INFO, "Uploaded " + p.getUploadSource().toString() + " to " + url); return true; // set auto-rotate only if we do the rotation in GR, otherwise we'd be overriding the server setting // if (p.getAngle() != 0) { // opts[5] = new NVPair("auto_rotate", "no"); // } // set up extra fields // if (p.getExtraFieldsMap() != null && p.getExtraFieldsMap().size() > 0) { // ArrayList optsList = new ArrayList(Arrays.asList(opts)); // // Iterator it = p.getExtraFieldsMap().keySet().iterator(); // while (it.hasNext()) { // String name = (String) it.next(); // String value = p.getExtraField(name); // // optsList.add(new NVPair("extrafield." + name, value, utf8?"UTF-8":null)); // } // } // // opts = (NVPair[]) optsList.toArray(opts); // } // load and validate the response // Properties props = requestResponse(hdrs, data, g.getGalleryUrl(scriptName), true, su, this, transferListener); // if (props.getProperty("status").equals(GR_STAT_SUCCESS)) { // status(su, StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "upSucc")); // String newItemName = props.getProperty("item_name"); // if (newItemName != null) { // su.doneUploading(newItemName, picture); // } // return true; // } else { // Object[] params = {props.getProperty("status_text")}; // error(su, GRI18n.getString(MODULE, "upErr", params)); // return false; // } } catch (GR2Exception gr2e) { Log.logException(Log.LEVEL_ERROR, MODULE, gr2e); Object[] params = {gr2e.getMessage()}; error(su, p.toString() + ": " + GRI18n.getString(MODULE, "error", params)); } catch (IOException ioe) { Log.logException(Log.LEVEL_ERROR, MODULE, ioe); Object[] params = {ioe.toString()}; error(su, p.toString() + ": " + GRI18n.getString(MODULE, "error", params)); } return false; }