501_remote/app.py

35 lines
978 B
Python

import os
from flask import Flask, request, send_file
from flask_restful import Resource, Api, reqparse
app = Flask(__name__)
api = Api(app)
class ObjectStorage(Resource):
# @app.route('/objects/', methods=['GET', 'POST', 'PUT'])
def put(self, object_name):
file = request.files['file']
file.save(object_name)
return {'status': 'success'}
# @app.route('/objects/', methods=['GET', 'POST', 'PUT'])
def get(self, object_name):
file = open(object_name, 'rb')
return send_file(file, mimetype='application/octet-stream')
# @app.route('/objects/', methods=['GET', 'POST', 'PUT'])
def delete(self, object_name):
os.remove(object_name)
return {'status': 'success'}
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
api.add_resource(ObjectStorage, '/objects/<string:object_name>')
if __name__ == '__main__':
app.run()