From 338498cef1cd4f2b9ae49bc54bd496de0e5472a0 Mon Sep 17 00:00:00 2001 From: mnandri Date: Wed, 16 Dec 2015 16:35:33 +0100 Subject: WIP: rename me later --- service/pixelated/resources/attachments_resource.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'service/pixelated/resources/attachments_resource.py') diff --git a/service/pixelated/resources/attachments_resource.py b/service/pixelated/resources/attachments_resource.py index 667d030e..2b5a6912 100644 --- a/service/pixelated/resources/attachments_resource.py +++ b/service/pixelated/resources/attachments_resource.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . +import cgi import io import re @@ -78,16 +79,24 @@ class AttachmentsResource(Resource): def getChild(self, attachment_id, request): return AttachmentResource(self.mail_service, attachment_id) - def render_POST(self, request): - _file = request.args['attachment'][0] + def render_GET(self, request): + return '

' \ + '
' \ + '

' \ + '

' \ + '' - deferred = self.mail_service.attachment_id(_file) + def render_POST(self, request): + fields = cgi.FieldStorage(fp=request.content, headers=request.headers, environ={'REQUEST_METHOD':'POST'}) + _file = fields['attachment'] + deferred = defer.maybeDeferred(self.mail_service.attachment_id, _file.value, _file.type) def send_location(attachment_id): request.headers['Location'] = '/%s/%s'% (self.BASE_URL, attachment_id) respond_json_deferred({"attachment_id": attachment_id}, request, status_code=201) def error_handler(error): + print error respond_json_deferred({"message": "Something went wrong. Attachement not saved."}, request, status_code=500) deferred.addCallback(send_location) -- cgit v1.2.3