def save_attachment(self, doc_id, revision, attachment): attachment = IAttachmentPrivate(attachment) uri = ('/%s/%s/%s?rev=%s' % (self.db_name, quote(doc_id.encode('utf-8')), quote(attachment.name), revision.encode('utf-8'))) headers = {'content-type': attachment.content_type} body = attachment.get_body() if isinstance(body, unicode): body = body.encode('utf-8') d = self.couchdb_call(self.couchdb.put, uri, body, headers=headers) return d
def save_attachment(self, doc_id, revision, attachment): attachment = IAttachmentPrivate(attachment) uri = ('/%s/%s/%s?rev=%s' % (self.db_name, urllib.quote(doc_id.encode('utf-8')), urllib.quote(attachment.name), revision.encode('utf-8'))) headers = {'Content-Type': [attachment.content_type]} body = attachment.get_body() body = body.encode('utf-8') d = self._lock_document(doc_id, self._paisley_call, doc_id, self.paisley.put, uri, body, headers=headers) d.addCallback(self.paisley.parseResult) return d
def save_attachment(self, doc_id, revision, attachment): attachment = IAttachmentPrivate(attachment) doc = self._documents.get(doc_id) if not doc: return defer.fail(NotFoundError(doc_id)) if '_attachments' not in doc: doc['_attachments'] = dict() doc['_attachments'][attachment.name] = dict( stub=True, content_type=attachment.content_type, length=attachment.length) self._attachments[doc['_id']][attachment.name] = attachment.get_body() self._set_id_and_revision(doc, doc_id) r = Response(ok=True, id=doc['_id'], rev=doc['_rev']) return defer.succeed(r)