/** * Write an Attachment for a given Document * * @param docId * @param attachName * @param mimeType e.g. "image/jpeg" * @param in */ public void writeAttachment(String docId, String attachName, String mimeType, InputStream in) { try { Document doc = database.getDocument(docId); UnsavedRevision newRev = doc.getCurrentRevision().createRevision(); newRev.setAttachment(attachName, mimeType, in); newRev.save(); } catch (CouchbaseLiteException e) { e.printStackTrace(); } }
/** * Remove an Attachment from a Document * * @param docId * @param attachName */ public void deleteAttachment(String docId, String attachName) { try { Document doc = database.getDocument(docId); UnsavedRevision newRev = doc.getCurrentRevision().createRevision(); newRev.removeAttachment(attachName); // (You could also update newRev.properties while you're here) newRev.save(); } catch (CouchbaseLiteException e) { e.printStackTrace(); } }
@Kroll.setProperty(name = "userProperties") public void setUserProperties(KrollDict properties) { ((UnsavedRevision) revision).setUserProperties(properties); }
@Kroll.method public void setPropertyForKey(String key, Object value) { ((UnsavedRevision) revision).getProperties().put(key, value); }
@Kroll.setProperty(name = "isDeletion") public void setDeletion(boolean deletion) { ((UnsavedRevision) revision).setIsDeletion(deletion); }
@Kroll.method public void setAttachment(String name, String contentType, TiBlob content) { ((UnsavedRevision) revision).setAttachment(name, contentType, content.getInputStream()); }
@Kroll.method public void removeAttachment(String name) { ((UnsavedRevision) revision).removeAttachment(name); // TODO attachment cache }