Apps in Domino do not sync files back to project, so in order to update a file from a Domino app one must use the Domino REST API, or the python wrapper. Following below is an example of using the REST API for this purpose:
# Sample script for using the Domino API to upload a file.
# This script will create a file called "myfile.txt" in the project root
# then upload that same file to results/uploaded.txt
# The API call being used is: PUT https://api.dominodatalab.com/v1/projects/username/project_name/path
# This is documented here: https://dominodatalab.github.io/api-docs/#/reference/project-runs-and-files/file-uploads/upload-a-file-to-a-project
# Run this from any project to test, no additional inputs are required.
import os
import requests
# Get some Domino environment variables
domino_api_key = os.environ["DOMINO_USER_API_KEY"]
domino_project = os.environ["DOMINO_PROJECT_NAME"]
domino_user = os.environ["DOMINO_STARTING_USERNAME"]
domino_api_host = os.environ['DOMINO_API_HOST']
# Create a sample file
with open('myfile.txt', 'w') as f:
f.write('hello world')
# Supply the API key for our request
headers = {
'X-Domino-Api-Key': domino_api_key,
'Content-Type': 'application/json'
}
# Specify the full path we want the file to be uploaded, without "/mnt"
file_path = 'results/uploaded.txt'
# The endpoint is the API we want to call
endpoint = 'v1/projects/{}/{}/{}'.format(domino_user, domino_project, file_path)
# The URL is the API host plus the endpoint
url = '{}/{}'.format(domino_api_host, endpoint)
# Read the file contents as bytes
with open('myfile.txt', 'rb') as f:
contents = f.read()
# Make the API call to upload the file. Check the results folder in the project files section to see the "uploaded.txt" file.
response = requests.request('PUT', url, headers = headers, data = contents)
For an example that uses the python wrapper, please see the following article:
https://tickets.dominodatalab.com/hc/en-us/articles/4411401974548
Comments
0 comments
Please sign in to leave a comment.