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.
- Could someone verify that my yaml spec is correct? (I am choosing file type, because the only other data type I could use to upload a photo is string, with format Byte, but that would lead in an overhead to convert the photo in string.
- If it is indeed correct, does anyone know if there is a way to get an
NSURL
from aUIImage
. 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 anNSURL
which seems hacky. So should I change the generated implementation to accept anNSData
type, or do you have anything better to suggest?