I want to post an image using the generated swift-client. After a lot of researching I think the best way to specify this is:
/user/profilepicture:
put:
description: |
upload profile picture of user
consumes:
- multipart/form-data
parameters:
- name: profilePhoto
in: formData
type: file
The generated swift client function signature is:
public class func usersProfilepicturePut(profilePhoto profilePhoto: NSURL? = nil, completion: ((error: ErrorType?) -> Void))
The problem I am having is the NSURL
type. The reason is that it seems very difficult to get an NSURL
out of a UIImage
, especially if the photo has been taken from the camera with the UIImagePickerController
.
Then again I do not want to change the type of the parameter to a string, and use a base64 encoding because it adds a lot of overhead to convert the image to a string.
NSURL
from a UIImage
. This second question exists, however the answer in [Getting the URL of picture taken by camera with Photos Framework does not return a URL but a string identifier. Also other answers to similar questions all suggest to save the image and then retrieve it again just to get an NSURL
which seems hacky.
So should I change the generated implementation to accept an NSData
type, or do you have anything better to suggest?Looks like the swagger API at the time of writing is Base64 encoding NSData into the post. So avoid that if you don't want to use Base64 or if don't want to extend/modify the swagger generated code.
To send binary data looks like you need a NSURL of the local file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With