Sommaire

Asynchronous files manager (Drive)

Usage

Files are to big to be send inside HTTP request, so we created Drive.
Drive is a REST API you want to use for sending files.

import

Route

To sending information to drive you will use the package requests
requests is a package that allow you to do GET and POST HTTP request
Here is a guide of the library : https://realpython.com/python-requests/

Register

You need as you see in the image before to register to the drive. When you register you need to give some information about you :

Route: '/register', methods=['POST']  
Requires a json body:  
{"app": "", "path": "", "route": ""}  
app : the name of your app  
path : the path where you want to recieve the files the others are sending to you  
route : the route wich Drive will call to tell you that a file was send to you.  
You need to create this route, as a POST method where we will send  
you a json body : {"app": "", "path": ""}  
with app : the name of the sender and path : the path of the file sent.

concretely :

r = requests.post('http://127.0.0.1:5001/register', data={'app': 'magasin',
                                                              'path': 'C:\\app\\magasin\\directory',
                                                              'route': 'http://127.0.0.1:5xxx/newfile'})

don’t forget to create your own route!
Exemple :

@app.route('/newfile', methods=['POST'])
def newfile():
    req_data = request.get_json()

    app = req_data['app'] # the name of the sender
    path = req_data['path'] # the path where you will find the file
    return 200

Unregister

A simple route to unregister your app, useful in some case

Route: '/unregister', methods=['POST']  
Requires a json body:  
{"app": ""}  
app : the name of your app  

concretely :

r = requests.post('http://127.0.0.1:5001/unregister', data={'app': 'magasin'})

Send

For sending a file just do a POST request to the drive.

Route: '/send', methods=['POST']  
Requires a json body:  
{"me": "", "app": "", "path": "", "name_file": ""}
me : the name of your app  
app : the name of the app you are sending the file  
path : the path of the file you want to send
name_file : Optional but the name the file will get

concretely :

r = requests.post('http://127.0.0.1:5001/send', data={'me': 'magasin',
                                                              'app': 'crm',
                                                              'path': 'C:\\app\\magasin\\file_to_send'})

Manage

The queue systems will be launch with the scheduler, but for now, to test locally the drive app you need to start yourself the queue systems by calling :

r = requests.post('http://127.0.0.1:5001/manage')