I want to upload some files for a specific workbench using HTTP.
I'm using Python for this with requests library, but I'm having difficulty getting it to work.
My python code is as follows:
with open(file_path, 'rb') as file:
url = f"{fme_url}/fmedataupload/{script_location}"
data = {
'custom_file': {
'value': file.read(),
'options': {
'contentType': 'application/octet-stream',
'filename': file_name,
}
},
'opt_namespace': directory,
'opt_fullpath': True
}
token = get_token()
headers = {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': f"fmetoken token={token}",
}
return requests.post(url, data=data, headers=headers, json=True)
I do get a 200 OK response, so authorization is fine, but the file isn't uploaded.
It even creates a directory at the right spot.
The response is as follows
<Response u200]>
{"serviceResponse": {
"statusInfo": {"status": "success"},
"session": "foo",
"files": {
"path": "",
"folder": l{
"path": "$(FME_DATA_REPOSITORY)/main_repository/script_name.fmw/foo",
"name": ""
}]
}
}}
The data upload documentation (https://docs.safe.com/fme/html/FME_Server_Documentation/ReferenceManual/service_dataupload.htm) simply lists 'Upload a single file or multiple files using a simple form submission that uses HTTP POST.', which is not helpful.
I'm using Python 3.8 and FME server 2019.2
My goal is to upload the required files, then start a workbench, and finally retrieve the result, all using Python. Preferably, the FME server account that Python uses has as little permissions as possible.