POST image with fast client from generated code

I want to publish an image using the generated swift client. After many studies, I find the best way to point this out:

/user/profilepicture: put: description: | upload profile picture of user consumes: - multipart/form-data parameters: - name: profilePhoto in: formData type: file 

The generated fast client signaling function:

 public class func usersProfilepicturePut(profilePhoto profilePhoto: NSURL? = nil, completion: ((error: ErrorType?) -> Void)) 

The problem I am facing is the type of NSURL . The reason is that it is very difficult to get NSURL from UIImage , especially if the photo was taken from the camera using the UIImagePickerController .

Then again, I don’t want to change the type of the parameter in the string and use base64 encoding, because it adds a lot of overhead to convert the image to a string.

  • Can someone check if yaml specification is correct? (I choose the file type because the only other data type I could use to upload the photo is a string with a format byte, but this can lead to overhead to convert the photo to a string.
  • If this is really correct, does anyone know if there is a way to get NSURL from UIImage . This second question exists, however, the answer in [ Obtaining the URL of a picture taken by the camera using the Photos Framework does not return the URL, but a string identifier. In addition, other answers to similar questions suggest saving the image and then restoring it again to get an NSURL that seems hacked. So do I have to modify the generated implementation to accept the NSData type, or is it better for you to suggest?
+5
source share
1 answer

It looks like the swagger API at the time of writing is Base64-encoded NS64. Therefore, avoid this if you do not want to use Base64, or if you do not want to extend / modify the code generated by swagger.

To send binary data, it looks like you need a NSURL local file.

0
source

Source: https://habr.com/ru/post/1257683/


All Articles