I know that this question has been asked before a few times, here, here and possibly many more times. I've tried all of those answers, but none of them work for what I am trying to do.
Essentially, I am attempting to connect a UIImage to the Kairos API
. I'm making a simple POST request, with a source
parameter in the request. The request returns a JSON object with various datapoints that I would like to use in my application. Most of the answers that I have seen about uploading image files use a multipart-form-data
request to do it, but I'm not sure about how this would connect to the source
parameter the API is asking for in the request. I know how I can add in the authentication section as a header to my URLRequest
, I just need help with uploading the image as the source
parameter.
This CURL
code works:
curl -X POST -H "app_id: XXX" -H "app_key: YYY" -F "source=@/Users/myusername/Desktop/myimage.jpg" "https://api.kairos.com/v2/media"
However, I'm not sure how I can convert such code to Swift.
Preferably, I'd like to use traditional URLRequests and URLSessions
rather than third-party external libraries (due to a couple of blog posts that I've read which mention the danger of using third-party libraries at times). Can anyone help me to do this?
Thanks in advance!