Document Attachments API¶
Soledad Documents implement the IDocumentWithAttachment
API that associates
Blobs with documents.
-
class
leap.soledad.client._document.
IDocumentWithAttachment
[source]¶ Bases:
zope.interface.Interface
A document that can have an attachment.
-
delete_attachment
()¶ Delete the attachment of this document.
The pointer to the attachment will be removed from the document content, but the document has to be manually put in the database to reflect modifications.
Returns: A deferred which fires when the attachment has been deleted from local storage. Return type: Deferred
-
download_attachment
()¶ Download this document’s attachment.
Returns: A deferred which fires with the state of the attachment after it’s been downloaded, or NONE if there’s no attachment for this document. Return type: Deferred
-
get_attachment
()¶ Return the data attached to this document.
If document content contains a pointer to the attachment, try to get the attachment from local storage and, if not found, from remote storage.
Returns: A deferred which fires with a file like-object whose content is the attachment of this document, or None if nothing is attached. Return type: Deferred
-
get_attachment_state
()¶ Return the state of the attachment of this document.
The state is a member of AttachmentStates and is of one of NONE, LOCAL, REMOTE or SYNCED.
Returns: A deferred which fires with The state of the attachment of this document. Return type: Deferred
-
is_dirty
()¶ Return whether this document’s content differs from the contents stored in local database.
Returns: A deferred which fires with True or False, depending on whether this document is dirty or not. Return type: Deferred
-
put_attachment
(fd)¶ Attach data to this document.
Add the attachment to local storage, enqueue for upload.
The document content will be updated with a pointer to the attachment, but the document has to be manually put in the database to reflect modifications.
Parameters: fd (file-like) – A file-like object whose content will be attached to this document. Returns: A deferred which fires when the attachment has been added to local storage. Return type: Deferred
-
set_store
(store)¶ Set the store used by this file to manage attachments.
Parameters: store (Soledad) – The store used to manage attachments.
-
upload_attachment
()¶ Upload this document’s attachment.
Returns: A deferred which fires with the state of the attachment after it’s been uploaded, or NONE if there’s no attachment for this document. Return type: Deferred
-