Back to help overview
Back to API functionality

File upload API

Upload files

This function will upload files to the ARISE MDS server and at the appropriate file object in the database.

Fields

Requires files and data.

Data fields

device : Required if deployment or device token is not supplied. devicelabel of a device in the database. Deployment will automatically be chosen based on the dt of files (see below)

deployment : Required if device or device token is not supplied. deploymentdeviceID of a deployment in the database.

dt : Required if files are not images, recommended to provide even if files are images List of date - times in the format %Y-%m-%d %H:%M:%S. If not a list or if a list of only one element, this date-time will be repeated for all files.

rename : Defaults to True Automatically rename files in the system to the default naming scheme. Please use this if you have not already renamed your files.

autoupdate : Defaults to False Flag the deployment as autoupdating or not. Set this to true if the API call is made by an automated device. Set to False if you are uploading data manually.

extrainfo : Not required JSON of other attributes to append to the file in the metadata. Can take two forms. 1) The ORIGINAL names of the files to be uploaded (including extension) are in the top level keys, in which case nested data is matched per-file. 2) Original names of the files are not included in top level keys, in which case the JSON is repeated for every file.

checkfilename : Defaults to True Check if a datafile exists in the database with the same originalname as the pre-upload name of each file. If the file already exists, it will be skipped.

Code examples

Python

api_url = "https://arisemdsvm.science.uva.nl//api-token-auth/"       
response = requests.post(api_url,{"username":username,"password":password})
token=response.json()['token']

#Assign files to a specific deployment
api_url = "https://arisemdsvm.science.uva.nl//api/Fileupload/" 
response = requests.post(api_url,
                         headers={'Authorization': 'token {}'.format(token)},
                         files =[
                             ("file",open("myfile1.JPG",'rb')),
                             ("file",open("myfile2.JPG",'rb'))
                             ],
                         data={"deployment":"mydeploymentid",
                               "autoupdate":True,
                               "dt":["2022-09-28 00:00:00","2022-09-27 00:00:00"],
                               "rename":True,
                "checkfile":True, # Check datafile with originalname "myfile1.JPG" do not exist already.
                               "extrainfo":json.dumps({"myfile1.JPG":{"test":"foo"},
                                            "myfile2.JPG":{"test":"bar"}})
                               }
                         )
print(response.json())


#assign a file to a device using a device token

response = requests.post(api_url,
                         headers={'DeviceToken': devicetoken},
                         files =[
                             ("file",open("myfile3.JPG",'rb')),
                             ("file",open("myfile4.JPG",'rb'))
                             ],
                         data={
                               "autoupdate":True,
                               "dt":["2022-09-26 00:00:00","2022-09-25 00:00:00"],
                               "rename":True,
                "checkfile":True,
                               "extrainfo":json.dumps({"myfile3.JPG":{"test":"foo"},
                                            "myfile4.JPG":{"test":"bar"}})
                               }
                         )
print(response.json()

#assign a file to a device

response = requests.post(api_url,
                         headers={'Authorization': 'token {}'.format(token)},
                         files =[
                             ("file",open("myfile3.JPG",'rb')),
                             ("file",open("myfile4.JPG",'rb'))
                             ],
                         data={"device":"mydeviceid",
                               "autoupdate":True,
                               "dt":["2022-09-26 00:00:00","2022-09-25 00:00:00"],
                               "rename":True,
                "checkfile":True,
                               "extrainfo":json.dumps({"myfile3.JPG":{"test":"foo"},
                                            "myfile4.JPG":{"test":"bar"}})
                               }
                         )
print(response.json())

Details

URL : api/Fileupload/

Method : PUT

Auth required : YES

Permissions required : Create DataFile objects OR a valid device token

File constraints

Files must be provided

Data constraints

{
    "deployment": "[required if no deploymkent devicelabel of device already in the database]",
    "deployment": "[required if no device devicedeploymentID of deployment already in the database]",
    "autoupdate": "[Boolean, defaults to False]",
    "checkfile": "[Boolean, defaults to True]",
    "rename": "[Boolean, defaults to True]",
    "dt":"[not required for images, list of date times the same length as the number of files provided in the format %Y-%m-%d %H:%M:%S]",
    "extrainfo":["not required, either a JSON where every top level key is the ORIGINAL name of a file being uploaded or just a JSON that will be repeated for every file"]   
    "observations":["not required, JSON of observed species to attach to the uploaded files. Each element must take the following format. 
    A 'files' key, containing a list of all files to which the observation will be attached. These must be the ORIGINAL names of the files to be uploaded (including extension). 
    An 'observation' key, containing the following keys:
        'observation': Taxonomic species name or 'None' if there is no animal.
        'source': Where this observation was obtained.
        'number': How many of this species are in the files.
        'data': JSON containing any additional fields/original data output etc."]                   
}

```