User Tools


Download a User's File

Back to JEA API docs


Files that have been uploaded by the user to the JEA service can be downloaded with the auto-generated file ID. A valid JWT token must be included in the header, or the transaction will be rejected with an HTTP 401 Unauthorized error code.


Synopsis

Example using curl://

To download the file with ID command using curl:

curl -H "Authorization:Bearer eyJraWQiOiIxNT...9gjFXUrpQ"  http://jea.ensims.com/jea_web/api/download/d07b790c956e0fa5036b420edce2f5f0 > dn.png

On successful operation, the contents of the requested file is returned. If the existing JWT is invalid, an HTTP 401 Unauthorized code will be returned.

Example using Python Requests

Make sure Requests is correctly installed in your Python environment, and run the following the lines:

import requests

jwt = 'eyJraWQiOiIxNTAy...yBqDDTkfjmsQons9gjFXUrpQ'
headers = {'Authorization': 'Bearer ' + jwt}
body = {}

# Download a previously uploaded file. The example is a png image
r = requests.get('http://jea.ensims.com/jea_web/api/download/d07b790c956e0fa5036b420edce2f5f0', headers=headers, json=body, stream=True)

# Write downloaded file content to disk using the given file name
filename = 'dn.png'
with open(filename, 'wb') as fd:
    for chunk in r.iter_content(chunk_size=128):
        fd.write(chunk)


Site Tools