diff options
author | mnandri <mnandri@eunglick.corporate.thoughtworks.com> | 2015-12-16 16:35:33 +0100 |
---|---|---|
committer | mnandri <mnandri@eunglick.corporate.thoughtworks.com> | 2015-12-18 11:22:34 +0100 |
commit | 338498cef1cd4f2b9ae49bc54bd496de0e5472a0 (patch) | |
tree | c64272dc1f7bb8502974f6993cda33b157f31cf2 /service/pixelated/resources | |
parent | f8ac23150f5f840eaa4ef920b003966f911de8fa (diff) |
WIP: rename me later
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r-- | service/pixelated/resources/attachments_resource.py | 15 |
1 files changed, 12 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>. +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 '<html><body><p></p>' \ + '<form method="POST" enctype="multipart/form-data">' \ + '<input name="attachment" type="file" /> <p></p>' \ + '<input type="submit" /></form><p></p>' \ + '</body></html>' - 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) |