diff --git a/client/client/__init__.py b/client/client/__init__.py index fccd82a..ebf9f1a 100755 --- a/client/client/__init__.py +++ b/client/client/__init__.py @@ -17,18 +17,43 @@ def request_url(path): #r = requests.get(request_url('/files'), params=payload, auth=('bam', 'bam')) #print (r.json()) -payload = { - 'filepath': 'shots', - 'command' : 'info', - } +# payload = { +# 'filepath': 'shots', +# 'command' : 'info', +# } -r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True) -local_filename = payload['filepath'].split('/')[-1] +# r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True) +# local_filename = payload['filepath'].split('/')[-1] -print (r.json()) +# print (r.json()) # with open(local_filename, 'wb') as f: # for chunk in r.iter_content(chunk_size=1024): # if chunk: # filter out keep-alive new chunks # f.write(chunk) # f.flush() # print(local_filename) + +# filepath = 'yourfilename.txt' +# with open(filepath) as fh: +# mydata = fh.read() +# response = requests.put('https://api.elasticemail.com/attachments/upload', +# data=mydata, +# auth=('omer', 'b01ad0ce'), +# headers={'content-type':'text/plain'}, +# params={'file': filepath} +# ) + +payload = { + 'command' : 'checkin', +} + +files = {'file': open('buck.mp4', 'rb')} +#files = {'name': ('filename', (open('mytest.txt', 'rb')))} + +r = requests.put(request_url('/file'), + params=payload, + auth=('bam', 'bam'), + files=files) + +print(r.text) + diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index ee34d42..6abc652 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -20,6 +20,7 @@ import os import svn.local import pprint +import werkzeug from flask import Flask, jsonify, abort, request, make_response, url_for, Response from flask.views import MethodView @@ -114,10 +115,12 @@ class FileAPI(Resource): def __init__(self): parser = reqparse.RequestParser() - parser.add_argument('filepath', type=str, required=True, + parser.add_argument('filepath', type=str, help="Filepath cannot be blank!") parser.add_argument('command', type=str, required=True, help="Command cannot be blank!") + parser.add_argument('files', type=werkzeug.datastructures.FileStorage, + location='files') args = parser.parse_args() super(FileAPI, self).__init__() @@ -152,6 +155,19 @@ class FileAPI(Resource): else: return jsonify(message='Command unknown') + + def put(self): + command = request.args['command'] + file = request.files['file'] + + if file and self.allowed_file(file.filename): + filename = werkzeug.secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + + return jsonify(message='Done') + else: + return jsonify(message='File not allowed') + @staticmethod def pack_fn(filepath): @@ -188,6 +204,11 @@ class FileAPI(Resource): return None + @staticmethod + def allowed_file(filename): + return '.' in filename and \ + filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] + api.add_resource(FilesListAPI, '/file_list', endpoint='file_list') api.add_resource(FileAPI, '/file', endpoint='file') diff --git a/webservice/bam/config.py.example.py b/webservice/bam/config.py.example.py index b68a893..2502c63 100644 --- a/webservice/bam/config.py.example.py +++ b/webservice/bam/config.py.example.py @@ -3,3 +3,5 @@ class Config(object): class Development(Config): STORAGE_PATH='/Volumes/PROJECTS/storage' + UPLOAD_FOLDER = '/Volumes/PROJECTS/storage_staging' + ALLOWED_EXTENSIONS = set(['txt', 'mp4', 'png', 'jpg', 'jpeg', 'gif', 'blend', 'zip'])