Environment
This article applies for all Domino platform versions as of the time of this writing.
Issue
While the benefits of using Datasets are enormous, there is the obstacle of downloading files from the UI or any other method (API) . At present there is no functionality build to do this outside of a workspace . In this article we will review a method for downloading files via a small flask application.
Resolution
We are using a few components to put together an app which will allow for browsing and downloading
files from our attached datasets.
Setting up flask app and routing:
The code for the app:
https://github.com/MrAmbiG/folderview
Important: To setup the application we will require to first setup an environment which satisfies the code requirements. See requirements.txt and make sure you have the required packages.
Once the environment is setup we can start adding our files.
To start the application we will use app.sh with the following content:
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export FLASK_APP=app.py
export FLASK_DEBUG=1
python -m flask run --host=0.0.0.0 --port=8888
And for the application file we will use app.py file with the following content:
# app.py
from flask import Flask
from flask_autoindex import AutoIndex
app = Flask(__name__)
ppath = "/domino/datasets/local/"
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
return self.app(environ, start_response)
app = Flask(__name__)
AutoIndex(app, browse_root=ppath)
app.wsgi_app = ReverseProxied(app.wsgi_app)
if __name__ == "__main__":
app.run()
Note: the variable "ppath" is set to "/domino/datasets/local/" which is the mountpoint of all attached datasets to the current project . This is where you can change the base/root folder of our app . Before starting the app make sure you have attached the required datasets.
Once we have our files in place we need to start the application.
Note: It is possible to use curl to pull files from the application however you will be required to use
the authentication token. An easy way to construct the curl request is to copy it from the
developer console/networking tab , which will contain your authentication details .
curl 'https://<DOMINO DEPLOYMENT URL>/<USERNAME>/<PROJECT>/r/notebookSession/<SESSION ID>/TEST_DOWNLOAD/test_file.txt' \
-H 'Cookie: dominoSession=<SESSION ID>; PLAY_SESSION=<ID>; kc_session_state=<ID>' \
--output ./test_file.txt
Comments
0 comments
Article is closed for comments.