Adding support for File Storage on Attract Server

This commit is contained in:
Eibriel
2015-04-23 16:01:55 -03:00
parent 9fc01b219c
commit d00676ce4e
3 changed files with 19 additions and 4 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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()