User Tools


Upload a File to JEA

Back to JEA API docs


A user can upload files to the JEA service using the Upload operation. A typical use case is that uploading all project files zipped into an archive for safekeeping or sharing. A successful upload to be stored with an auto-generated file ID, instead of the original file name. Subsequent download operations must reference this ID. It will not be possible to obtain the original file name from the server, hence the client program or the user should keep track of the uploaded files.

When uploading a file, a valid JWT token must be included in the header, or the transaction will be rejected with an HTTP 401 Unauthorized error code.


Synopsis

  • Method: POST
  • Header: Authorization: “Bearer <existing JWT>”, Content-Type: “application/octet-stream”
  • Body: File contents as Multi-part Form Data
  • Success: Upload Info object
  • Error: HTTP 401 - Unauthorized

Upload Info

If the uploaded file is successfully received and stored by the server, it will return an acknowledgment containing the status and the file ID (fileHandle). Also returned is a callback link which is not currently in use.

{
  "ok" : true,
  "status" : "File upload accepted",
  "fileHandle" : "d07b790c956e0fa5036b420edce2f5f0",
  "callback" : "http://jea.ensims.com/jea_web/api/view/d07b790c956e0fa5036b420edce2f5f0"
}

Example using curl://

To download the file with ID command using curl:

curl -H "Authorization:Bearer eyJraWQiOiIxNT...9gjFXUrpQ" -F "file=@dn.png" http://jea.ensims.com/jea_web/api/upload

On successful operation, an Upload Info object 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 = {}

# Upload a file. The example is a png image
url = 'http://jea.ensims.com/jea_web/api/upload'
files = {'file': open('dn.png', 'rb')}
r = requests.post(url, headers=headers, files=files)

r.json()['fileHandle']


Site Tools