-
REST API Client – POST file
Dear $all,
I have found valuable input in this thread (https://www.omnis.net/community/forums/forum/discussion/picture-upload-via-api/), but for my particular problem, I still have a missing link.I would like upload a file with the OMNIS REST API client to an REST API service of another app, but I keep getting ‘Internal Server Error’. The API endpoint does work, if I test it with Curl or Postman, I can upload the file.
My Omnis code goes as follows:
Calculate iHTTPMethod as kOW3httpMethodPost
Calculate icContentType as 'multipart/form-data'
Do iHeadersList.$clear()
Do iHeadersList.$add("Authorization","Bearer 3288b990-703a-11ef-9b57-290f46ee5e30")
Do iHeadersList.$add("Content-Type","multipart/form-data")
Calculate iURI as con("https://api.ninox.com/v1/teams/EjnXhyYwG2hZYxX6A/databases/tz8mz96j4nt0/tables/A/records/1/files")
Do loFileOps.$openfile('/Users/usmidt/Desktop/Aruba.png')
Do loFileOps.$readfile(lbinContent)
Do loFileOps.$closefile()
Calculate lcFileBase64 as utf8tochar(bintobase64(lbinContent))
Calculate iContentChar as con('data:image/png;base64,',lcFileBase64)
Do iRestfulObj.$init(iURI,iHTTPMethod,iHeadersList,iContentChar) Returns lStatus
Do iRestfulObj.$run() Returns lStatus
My problem seems to be the way I setup the body parameter of the POST, iContentChar. The REST service expects ‘multipart/form-data’, but how do I build the iContentChar?
PS: feel free to test against the API endpoint, it is just a trial app setup for this purpose, without real data or value.
PPS: the working Curl command iscurl --location 'https://api.ninox.com/v1/teams/EjnXhyYwG2hZYxX6A/databases/tz8mz96j4nt0/tables/A/records/1/files' \
--header 'Authorization: Bearer 3288b990-703a-11ef-9b57-290f46ee5e30' \
--header 'Content-Type: multipart/form-data' \
--form 'Robby3=@"/Users/usmidt/Desktop/Robby3.jpg"'
File Uploaded Successfully%
Any help is greatly appreciated!!!!!
Best regards
Uwe
Log in to reply.