Download from a Dataiku DSS Webapp¶
When building a webapp in Dataiku DSS, you may want to allow users to download a file from a managed folder. Here are steps to build an HTML button, which will allow webapp users to download files stored in a managed folder.
Basic Download¶
Here’s how you can download a file from a managed folder by clicking on a button in a webapp.
In the Python part of the webapp, define an endpoint like:
import dataiku
from flask import request
from flask import send_file
import io
@app.route('/downloadFile')
def first_call():
filename = request.args.get('filename')
stream = dataiku.Folder('FOLDER_ID').get_download_stream(filename)
with stream:
return send_file(
io.BytesIO(stream.read()),
as_attachment=True,
attachment_filename=filename)
Then in the Javascript section, you’d need a function like:
window.download = function(){
window.location.href = getWebAppBackendUrl('/downloadFile?filename=test.txt');
}
Finally, in the HTML you can add a button to trigger that JS function:
<button onclick="download()">Download</button>
What’s Next?¶
To learn more about webapps in Dataiku DSS, visit the Dataiku Academy for tutorials and examples.