From d00676ce4e3eee49130d33194a3065487b0552fd Mon Sep 17 00:00:00 2001 From: Eibriel Date: Thu, 23 Apr 2015 16:01:55 -0300 Subject: [PATCH] Adding support for File Storage on Attract Server --- attractsdk/api.py | 2 +- attractsdk/binary_files.py | 5 ++--- attractsdk/files.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/attractsdk/api.py b/attractsdk/api.py index 362765e..c62175e 100644 --- a/attractsdk/api.py +++ b/attractsdk/api.py @@ -101,7 +101,7 @@ class Api(object): if files and method in ['POST', 'PUT', 'PATCH']: return self.http_call( url, method, - data={'properties': {}}, + data=body, files=files, headers=http_headers) else: diff --git a/attractsdk/binary_files.py b/attractsdk/binary_files.py index 3133733..81e7add 100755 --- a/attractsdk/binary_files.py +++ b/attractsdk/binary_files.py @@ -14,14 +14,13 @@ class binaryFile(List, Find, Create, Post, Update, Delete, Replace): """ path = "binary_files" - def post_file(self, file_, api=None): - """Stores a file on the database. + def post_file(self, file_, api=None): + """Stores a file on the database or static folder. :param file: A file object """ api = api or self.api url = utils.join_url(self.path) files = {'data': file_} - print (files) new_attributes = api.post(url, {}, {}, files) # self.error = None self.merge(new_attributes) diff --git a/attractsdk/files.py b/attractsdk/files.py index 9e97fa8..9db8b22 100755 --- a/attractsdk/files.py +++ b/attractsdk/files.py @@ -6,8 +6,24 @@ from .resource import Update from .resource import Delete from .resource import Replace +from . import utils class File(List, Find, Create, Post, Update, Delete, Replace): """Node class wrapping the REST nodes endpoint """ path = "files" + file_server_path = "file_server/file" + + def post_file(self, file_path, name=None, api=None): + """Stores a file on the database or static folder. + :param file: A file object + """ + api = api or self.api + url = utils.join_url(self.file_server_path) + file_ = open(file_path, 'rb') + files = {'data': file_} + api.post(url, {"name": name}, {}, files) + file_.close() + # self.error = None + # self.merge(new_attributes) + return self.success()