Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3667

Getting image path for API post request

$
0
0

I am using an API post request in order to get a modified image.

curl \    -F 'image=@/path/to/your/file.jpg' \    -H 'api-key:[myKey]' \    [api url]

It worked fine directly on my Mac's terminal using:

curl \    -F 'image=@/Users/user/image.jpg' \    -H 'api-key:[myKey]' \    [api url]

Trying to use it in an iOS app, I'm struggling to get an image path.

The API works with Alamofire using another parameter that uses an image URL. So I thought to upload the image to a server and use that URL, but it would be much better if I could use directly the path parameter.

This is what I tried, but it doesn't work:

func imagePath(_ image: UIImage, handler: @escaping (String?) -> Void ) {    let path = NSTemporaryDirectory()        .appending(UUID().uuidString)        .appending("png")    let url = URL(fileURLWithPath: path)    let data = image.pngData()    let urlForApi = "@" + path    do {        try data?.write(to: url)        //  Just to check if write above works, it always works fine        let postData = try UIImage(data: Data(contentsOf: url))        handler (urlForApi)    } catch {        handler (nil)    }}

It returns handler (urlForApi), but the request gets an error. I'm not getting the correct path to use for the request.


Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>