You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`MultipartFormData` is a protocol, which provides default implementation for `ValidRequestData`. Implement this protocol to prepare any custom type to be uploaded as multipart form data.
175
+
176
+
## Image upload
177
+
178
+
As an optional extension `RESTAPIImage` adds a util implementation for `MultipartFormData` to upload a simple image. To perform an upload, just instantiate a new `JPGUploadMultipartFormData` instance with `UIImage` and send it as any other request.
179
+
180
+
`RESTAPIImage` is a sepatate framework, in order to use, add it to Carthage `copy-frameworks` phase and link it.
181
+
182
+
````swift
183
+
let uploadData =JPGUploadMultipartFormData(image: image, fileName: "image", uploadName: "upfile")
184
+
api.post("/me/profile_picture", data: uploadData) { (err, resp) in
185
+
//...
186
+
}
187
+
````
188
+
189
+
As all methods requre a `ValidRequestData` to send in body, uploading `JPGUploadMultipartFormData` is not different from any json upload besides composing the `httpBody` of the request. Any utils like authentication can be used, the response parsing is the same.
190
+
191
+
If the `JPGUploadMultipartFormData` implemetation is not suited for the current usecase, custom implemetnation for `MultipartFormData` can be implemented easily, like described [before](###Multipart-form-request)
192
+
170
193
## Authenticating requests
171
194
172
195
To authenticate a request, you have to set the `authentication` property of the API instance. For now this framework supports simple, access token based authentications in HTTP header and URL query. This is a simple example to show how to set up a HTTP header based authentication.
0 commit comments